bug reporting & a fix
This commit is contained in:
parent
07267562bc
commit
8414ab7ab3
14 changed files with 206 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
|
|
@ -11,6 +12,8 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/blog")]
|
||||
[AllowAnonymous]
|
||||
|
||||
public class BlogApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
|
@ -24,7 +27,7 @@ namespace Yavsc.Controllers
|
|||
[HttpGet]
|
||||
public IEnumerable<BlogPost> GetBlogspot()
|
||||
{
|
||||
return _context.Blogspot.Where(b=>b.Visible).OrderByDescending(b=>b.UserModified);
|
||||
return _context.Blogspot.Where(b => b.Visible).OrderByDescending(b => b.UserModified);
|
||||
}
|
||||
|
||||
// GET: api/BlogApi/5
|
||||
|
|
@ -145,4 +148,4 @@ namespace Yavsc.Controllers
|
|||
return _context.Blogspot.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
149
src/Yavsc/ApiControllers/Blogspot/PostTagsApiController.cs
Normal file
149
src/Yavsc/ApiControllers/Blogspot/PostTagsApiController.cs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using System.Security.Claims;
|
||||
using Models;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
[Produces("application/json")]
|
||||
[Route("~/api/PostTagsApi")]
|
||||
public class PostTagsApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public PostTagsApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/PostTagsApi
|
||||
[HttpGet]
|
||||
public IEnumerable<BlogTag> GetTagsDomain()
|
||||
{
|
||||
return _context.TagsDomain;
|
||||
}
|
||||
|
||||
// GET: api/PostTagsApi/5
|
||||
[HttpGet("{id}", Name = "GetPostTag")]
|
||||
public IActionResult GetPostTag([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlogTag postTag = _context.TagsDomain.Single(m => m.PostId == id);
|
||||
|
||||
if (postTag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(postTag);
|
||||
}
|
||||
|
||||
// PUT: api/PostTagsApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutPostTag(long id, [FromBody] BlogTag postTag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != postTag.PostId)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(postTag).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!PostTagExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/PostTagsApi
|
||||
[HttpPost]
|
||||
public IActionResult PostPostTag([FromBody] BlogTag postTag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.TagsDomain.Add(postTag);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (PostTagExists(postTag.PostId))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetPostTag", new { id = postTag.PostId }, postTag);
|
||||
}
|
||||
|
||||
// DELETE: api/PostTagsApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeletePostTag(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlogTag postTag = _context.TagsDomain.Single(m => m.PostId == id);
|
||||
if (postTag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.TagsDomain.Remove(postTag);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return Ok(postTag);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool PostTagExists(long id)
|
||||
{
|
||||
return _context.TagsDomain.Count(e => e.PostId == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
153
src/Yavsc/ApiControllers/Blogspot/TagsApiController.cs
Normal file
153
src/Yavsc/ApiControllers/Blogspot/TagsApiController.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using System.Security.Claims;
|
||||
using Models.Relationship;
|
||||
[Produces("application/json")]
|
||||
[Route("api/TagsApi")]
|
||||
public class TagsApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
ILogger _logger;
|
||||
|
||||
public TagsApiController(ApplicationDbContext context,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
_context = context;
|
||||
_logger = loggerFactory.CreateLogger<TagsApiController>();
|
||||
}
|
||||
|
||||
// GET: api/TagsApi
|
||||
[HttpGet]
|
||||
public IEnumerable<Tag> GetTag()
|
||||
{
|
||||
return _context.Tags;
|
||||
}
|
||||
|
||||
// GET: api/TagsApi/5
|
||||
[HttpGet("{id}", Name = "GetTag")]
|
||||
public IActionResult GetTag([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Tag tag = _context.Tags.Single(m => m.Id == id);
|
||||
|
||||
if (tag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(tag);
|
||||
}
|
||||
|
||||
// PUT: api/TagsApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutTag(long id, [FromBody] Tag tag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != tag.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(tag).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
_logger.LogInformation("Tag created");
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!TagExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/TagsApi
|
||||
[HttpPost]
|
||||
public IActionResult PostTag([FromBody] Tag tag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.Tags.Add(tag);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (TagExists(tag.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetTag", new { id = tag.Id }, tag);
|
||||
}
|
||||
|
||||
// DELETE: api/TagsApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteTag(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Tag tag = _context.Tags.Single(m => m.Id == id);
|
||||
if (tag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.Tags.Remove(tag);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return Ok(tag);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool TagExists(long id)
|
||||
{
|
||||
return _context.Tags.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue