no comment
This commit is contained in:
@ -5,6 +5,7 @@ using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
@ -21,7 +22,7 @@ namespace Yavsc.Controllers
|
||||
|
||||
// GET: api/BlogApi
|
||||
[HttpGet]
|
||||
public IEnumerable<Blog> GetBlogspot()
|
||||
public IEnumerable<BlogPost> GetBlogspot()
|
||||
{
|
||||
return _context.Blogspot.Where(b=>b.Visible).OrderByDescending(b=>b.UserModified);
|
||||
}
|
||||
@ -35,7 +36,7 @@ namespace Yavsc.Controllers
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Blog blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
|
||||
if (blog == null)
|
||||
{
|
||||
@ -47,7 +48,7 @@ namespace Yavsc.Controllers
|
||||
|
||||
// PUT: api/BlogApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutBlog(long id, [FromBody] Blog blog)
|
||||
public IActionResult PutBlog(long id, [FromBody] BlogPost blog)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
@ -82,7 +83,7 @@ namespace Yavsc.Controllers
|
||||
|
||||
// POST: api/BlogApi
|
||||
[HttpPost]
|
||||
public IActionResult PostBlog([FromBody] Blog blog)
|
||||
public IActionResult PostBlog([FromBody] Models.Blog.BlogPost blog)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
@ -118,7 +119,7 @@ namespace Yavsc.Controllers
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Blog blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
if (blog == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
|
@ -5,8 +5,7 @@ using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Relationship;
|
||||
|
||||
using Yavsc.Models.Blog;
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
|
148
Yavsc/ApiControllers/CommentsApiController.cs
Normal file
148
Yavsc/ApiControllers/CommentsApiController.cs
Normal file
@ -0,0 +1,148 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/blogcomments")]
|
||||
public class CommentsApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public CommentsApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/CommentsApi
|
||||
[HttpGet]
|
||||
public IEnumerable<Comment> GetComment()
|
||||
{
|
||||
return _context.Comment;
|
||||
}
|
||||
|
||||
// GET: api/CommentsApi/5
|
||||
[HttpGet("{id}", Name = "GetComment")]
|
||||
public async Task<IActionResult> GetComment([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
|
||||
if (comment == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(comment);
|
||||
}
|
||||
|
||||
// PUT: api/CommentsApi/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutComment([FromRoute] long id, [FromBody] Comment comment)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != comment.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(comment).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!CommentExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/CommentsApi
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostComment([FromBody] Comment comment)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
|
||||
_context.Comment.Add(comment);
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (CommentExists(comment.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetComment", new { id = comment.Id }, comment);
|
||||
}
|
||||
|
||||
// DELETE: api/CommentsApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteComment([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
|
||||
if (comment == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.Comment.Remove(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok(comment);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool CommentExists(long id)
|
||||
{
|
||||
return _context.Comment.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ namespace Yavsc.Controllers
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Blog blogpost = _context.Blogspot.Single(x=>x.Id == id);
|
||||
Models.Blog.BlogPost blogpost = _context.Blogspot.Single(x=>x.Id == id);
|
||||
|
||||
if (blogpost == null)
|
||||
{
|
||||
|
@ -7,8 +7,8 @@ using Microsoft.Data.Entity;
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using System.Security.Claims;
|
||||
using Models;
|
||||
using Models.Relationship;
|
||||
using Models;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
[Produces("application/json")]
|
||||
[Route("~/api/PostTagsApi")]
|
||||
|
Reference in New Issue
Block a user