bug reporting & a fix
This commit is contained in:
parent
07267562bc
commit
8414ab7ab3
14 changed files with 206 additions and 15 deletions
153
src/Yavsc/ApiControllers/Business/ActivityApiController.cs
Normal file
153
src/Yavsc/ApiControllers/Business/ActivityApiController.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/activity")]
|
||||
[AllowAnonymous]
|
||||
public class ActivityApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public ActivityApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/ActivityApi
|
||||
[HttpGet]
|
||||
public IEnumerable<Activity> GetActivities()
|
||||
{
|
||||
return _context.Activities.Include(a=>a.Forms).Where( a => !a.Hidden );
|
||||
}
|
||||
|
||||
// GET: api/ActivityApi/5
|
||||
[HttpGet("{id}", Name = "GetActivity")]
|
||||
public async Task<IActionResult> GetActivity([FromRoute] string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Activity activity = await _context.Activities.SingleAsync(m => m.Code == id);
|
||||
|
||||
if (activity == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
// Also return hidden ones
|
||||
// hidden doesn't mean disabled
|
||||
return Ok(activity);
|
||||
}
|
||||
|
||||
// PUT: api/ActivityApi/5
|
||||
[HttpPut("{id}"),Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> PutActivity([FromRoute] string id, [FromBody] Activity activity)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != activity.Code)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(activity).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!ActivityExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/ActivityApi
|
||||
[HttpPost,Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> PostActivity([FromBody] Activity activity)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.Activities.Add(activity);
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (ActivityExists(activity.Code))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetActivity", new { id = activity.Code }, activity);
|
||||
}
|
||||
|
||||
// DELETE: api/ActivityApi/5
|
||||
[HttpDelete("{id}"),Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> DeleteActivity([FromRoute] string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Activity activity = await _context.Activities.SingleAsync(m => m.Code == id);
|
||||
if (activity == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.Activities.Remove(activity);
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
|
||||
return Ok(activity);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool ActivityExists(string id)
|
||||
{
|
||||
return _context.Activities.Count(e => e.Code == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
src/Yavsc/ApiControllers/Business/PerformersApiController.cs
Normal file
66
src/Yavsc/ApiControllers/Business/PerformersApiController.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.Data.Entity;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Models;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Services;
|
||||
|
||||
[Produces("application/json")]
|
||||
[Route("api/performers")]
|
||||
public class PerformersApiController : Controller
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
private IBillingService billing;
|
||||
|
||||
public PerformersApiController(ApplicationDbContext context, IBillingService billing)
|
||||
{
|
||||
dbContext = context;
|
||||
this.billing = billing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists profiles on an activity code
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Roles="Performer"),HttpGet("{id}")]
|
||||
public IActionResult Get(string id)
|
||||
{
|
||||
var pfr = dbContext.Performers.Include(
|
||||
p=>p.OrganizationAddress
|
||||
).Include(
|
||||
p=>p.Performer
|
||||
).Include(
|
||||
p=>p.Performer.Posts
|
||||
).SingleOrDefault(p=> p.PerformerId == id);
|
||||
if (id==null)
|
||||
{
|
||||
ModelState.AddModelError("id","Specifier un identifiant de prestataire valide");
|
||||
}
|
||||
else {
|
||||
var uid = User.GetUserId();
|
||||
if (!User.IsInRole("Administrator"))
|
||||
if (uid != id) return new ChallengeResult();
|
||||
|
||||
if (!pfr.Active)
|
||||
{
|
||||
ModelState.AddModelError("id","Prestataire désactivé.");
|
||||
}
|
||||
}
|
||||
if (ModelState.IsValid) return Ok(pfr);
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
|
||||
[HttpGet("doing/{id}"),AllowAnonymous]
|
||||
public IActionResult ListPerformers(string id)
|
||||
{
|
||||
return Ok(dbContext.ListPerformers(billing, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
149
src/Yavsc/ApiControllers/Business/ProductApiController.cs
Normal file
149
src/Yavsc/ApiControllers/Business/ProductApiController.cs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
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;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Market;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/ProductApi")]
|
||||
public class ProductApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public ProductApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/ProductApi
|
||||
[HttpGet]
|
||||
public IEnumerable<Product> GetProducts()
|
||||
{
|
||||
return _context.Products;
|
||||
}
|
||||
|
||||
// GET: api/ProductApi/5
|
||||
[HttpGet("{id}", Name = "GetProduct")]
|
||||
public IActionResult GetProduct([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Product product = _context.Products.Single(m => m.Id == id);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(product);
|
||||
}
|
||||
|
||||
// PUT: api/ProductApi/5
|
||||
[HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
public IActionResult PutProduct(long id, [FromBody] Product product)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != product.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(product).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!ProductExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/ProductApi
|
||||
[HttpPost,Authorize(Constants.FrontOfficeGroupName)]
|
||||
public IActionResult PostProduct([FromBody] Product product)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.Products.Add(product);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (ProductExists(product.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetProduct", new { id = product.Id }, product);
|
||||
}
|
||||
|
||||
// DELETE: api/ProductApi/5
|
||||
[HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
public IActionResult DeleteProduct(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
Product product = _context.Products.Single(m => m.Id == id);
|
||||
if (product == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.Products.Remove(product);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return Ok(product);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool ProductExists(long id)
|
||||
{
|
||||
return _context.Products.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue