WIP billing
This commit is contained in:
parent
569cd74760
commit
62e1c49c1f
12 changed files with 1462 additions and 10 deletions
159
Yavsc/ApiControllers/EstimateTemplatesApiController.cs
Normal file
159
Yavsc/ApiControllers/EstimateTemplatesApiController.cs
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/EstimateTemplatesApi")]
|
||||
public class EstimateTemplatesApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public EstimateTemplatesApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/EstimateTemplatesApi
|
||||
[HttpGet]
|
||||
public IEnumerable<EstimateTemplate> GetEstimateTemplate()
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
return _context.EstimateTemplates.Where(x=>x.OwnerId==uid);
|
||||
}
|
||||
|
||||
// GET: api/EstimateTemplatesApi/5
|
||||
[HttpGet("{id}", Name = "GetEstimateTemplate")]
|
||||
public IActionResult GetEstimateTemplate([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
var uid = User.GetUserId();
|
||||
|
||||
EstimateTemplate estimateTemplate = _context.EstimateTemplates.Where(x=>x.OwnerId==uid).Single(m => m.Id == id);
|
||||
|
||||
if (estimateTemplate == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(estimateTemplate);
|
||||
}
|
||||
|
||||
// PUT: api/EstimateTemplatesApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutEstimateTemplate(long id, [FromBody] EstimateTemplate estimateTemplate)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != estimateTemplate.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
var uid = User.GetUserId();
|
||||
if (estimateTemplate.OwnerId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
return new HttpStatusCodeResult(StatusCodes.Status403Forbidden);
|
||||
|
||||
_context.Entry(estimateTemplate).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!EstimateTemplateExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/EstimateTemplatesApi
|
||||
[HttpPost]
|
||||
public IActionResult PostEstimateTemplate([FromBody] EstimateTemplate estimateTemplate)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
estimateTemplate.OwnerId=User.GetUserId();
|
||||
|
||||
_context.EstimateTemplates.Add(estimateTemplate);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (EstimateTemplateExists(estimateTemplate.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetEstimateTemplate", new { id = estimateTemplate.Id }, estimateTemplate);
|
||||
}
|
||||
|
||||
// DELETE: api/EstimateTemplatesApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteEstimateTemplate(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
EstimateTemplate estimateTemplate = _context.EstimateTemplates.Single(m => m.Id == id);
|
||||
if (estimateTemplate == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
var uid = User.GetUserId();
|
||||
if (estimateTemplate.OwnerId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
return new HttpStatusCodeResult(StatusCodes.Status403Forbidden);
|
||||
|
||||
_context.EstimateTemplates.Remove(estimateTemplate);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(estimateTemplate);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool EstimateTemplateExists(long id)
|
||||
{
|
||||
return _context.EstimateTemplates.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Yavsc/ApiControllers/PostRateApiController.cs
Normal file
47
Yavsc/ApiControllers/PostRateApiController.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/PostRateApi")]
|
||||
public class PostRateApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public PostRateApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/PostRateApi/5
|
||||
[HttpPut("{id}"),Authorize]
|
||||
public IActionResult PutPostRate([FromRoute] long id, [FromBody] int rate)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Blog blogpost = _context.Blogspot.Single(x=>x.Id == id);
|
||||
|
||||
if (blogpost == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var uid = User.GetUserId();
|
||||
if (blogpost.AuthorId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
return HttpBadRequest();
|
||||
|
||||
blogpost.Rate = rate;
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
146
Yavsc/ApiControllers/PostTagsApiController.cs
Normal file
146
Yavsc/ApiControllers/PostTagsApiController.cs
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[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<PostTag> GetTagsDomain()
|
||||
{
|
||||
return _context.TagsDomain;
|
||||
}
|
||||
|
||||
// GET: api/PostTagsApi/5
|
||||
[HttpGet("{id}", Name = "GetPostTag")]
|
||||
public IActionResult GetPostTag([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
PostTag 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] PostTag postTag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != postTag.PostId)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(postTag).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!PostTagExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/PostTagsApi
|
||||
[HttpPost]
|
||||
public IActionResult PostPostTag([FromBody] PostTag postTag)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.TagsDomain.Add(postTag);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
PostTag postTag = _context.TagsDomain.Single(m => m.PostId == id);
|
||||
if (postTag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.TagsDomain.Remove(postTag);
|
||||
_context.SaveChanges();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue