un positionnement de paramètre workflow des pros
This commit is contained in:
parent
fbd352e788
commit
96746fcc0b
322 changed files with 25893 additions and 3844 deletions
|
|
@ -144,7 +144,7 @@ namespace Yavsc.WebApi.Controllers
|
|||
/// <param name="me">MyUpdate containing the new user name </param>
|
||||
/// <returns>Ok when all is ok.</returns>
|
||||
[HttpPut("~/api/me")]
|
||||
public async Task<IActionResult> UpdateMe(MyUpdate me)
|
||||
public async Task<IActionResult> UpdateMe(UserInfo me)
|
||||
{
|
||||
if (!ModelState.IsValid) return new BadRequestObjectResult(
|
||||
new { error = "Specify some valid user update request." });
|
||||
|
|
|
|||
165
Yavsc/ApiControllers/BlackListApiController.cs
Normal file
165
Yavsc/ApiControllers/BlackListApiController.cs
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
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.Access;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/blacklist"), Authorize]
|
||||
public class BlackListApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public BlackListApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/BlackListApi
|
||||
[HttpGet]
|
||||
public IEnumerable<BlackListed> GetBlackListed()
|
||||
{
|
||||
return _context.BlackListed;
|
||||
}
|
||||
|
||||
// GET: api/BlackListApi/5
|
||||
[HttpGet("{id}", Name = "GetBlackListed")]
|
||||
public IActionResult GetBlackListed([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id);
|
||||
if (blackListed == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
return Ok(blackListed);
|
||||
}
|
||||
|
||||
private bool CheckPermission(BlackListed blackListed)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (uid != blackListed.OwnerId)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(Constants.FrontOfficeGroupName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// PUT: api/BlackListApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutBlackListed(long id, [FromBody] BlackListed blackListed)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != blackListed.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
_context.Entry(blackListed).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!BlackListedExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/BlackListApi
|
||||
[HttpPost]
|
||||
public IActionResult PostBlackListed([FromBody] BlackListed blackListed)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
_context.BlackListed.Add(blackListed);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (BlackListedExists(blackListed.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetBlackListed", new { id = blackListed.Id }, blackListed);
|
||||
}
|
||||
|
||||
// DELETE: api/BlackListApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteBlackListed(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id);
|
||||
if (blackListed == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
_context.BlackListed.Remove(blackListed);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(blackListed);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool BlackListedExists(long id)
|
||||
{
|
||||
return _context.BlackListed.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
using System;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models.Messaging;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Booking;
|
||||
|
||||
|
|
@ -40,14 +41,19 @@ namespace Yavsc.Controllers
|
|||
var now = DateTime.Now;
|
||||
|
||||
var result = _context.Commands.Include(c => c.Location).
|
||||
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now).
|
||||
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now
|
||||
&& c.ValidationDate == null).
|
||||
Select(c => new BookQueryProviderInfo
|
||||
{
|
||||
Client = new ClientProviderInfo { UserName = c.Client.UserName, UserId = c.ClientId },
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = c.Client.UserName,
|
||||
UserId = c.ClientId,
|
||||
Avatar = c.Client.Avatar },
|
||||
Location = c.Location,
|
||||
EventDate = c.EventDate,
|
||||
Id = c.Id,
|
||||
Previsional = c.Previsional
|
||||
Previsional = c.Previsional,
|
||||
Reason = c.Reason
|
||||
}).
|
||||
OrderBy(c=>c.Id).
|
||||
Take(25);
|
||||
|
|
|
|||
|
|
@ -6,33 +6,47 @@ using Microsoft.Data.Entity;
|
|||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Models;
|
||||
using ViewModels.Chat;
|
||||
[Route("api/chat")]
|
||||
public class ChatApiController : Controller
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
UserManager<ApplicationUser> userManager;
|
||||
public ChatApiController(ApplicationDbContext dbContext,
|
||||
UserManager<ApplicationUser> userManager)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
[HttpGet("users")]
|
||||
public List<ChatUserInfo> GetUserList()
|
||||
public IEnumerable<ChatUserInfo> GetUserList()
|
||||
{
|
||||
using (var db = new ApplicationDbContext()) {
|
||||
List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||
var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
||||
|
||||
var cxsQuery = db.Connections.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
||||
// List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||
if (cxsQuery!=null)
|
||||
foreach (var g in cxsQuery) {
|
||||
|
||||
List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||
|
||||
foreach (var g in cxsQuery) {
|
||||
|
||||
var uid = g.Key;
|
||||
var cxs = g.ToList();
|
||||
var uid = g.Key;
|
||||
var cxs = g.ToList();
|
||||
if (cxs !=null)
|
||||
if (cxs.Count>0) {
|
||||
var user = cxs.First().Owner;
|
||||
|
||||
result.Add(new ChatUserInfo { UserName = user.UserName,
|
||||
UserId = user.Id, Avatar = user.Avatar, Connections = cxs } );
|
||||
|
||||
}
|
||||
return result;
|
||||
if (user!=null ) {
|
||||
result.Add(new ChatUserInfo { UserName = user.UserName,
|
||||
UserId = user.Id, Avatar = user.Avatar, Connections = cxs,
|
||||
Roles = ( userManager.GetRolesAsync(user) ).Result.ToArray() });
|
||||
}
|
||||
else {
|
||||
result.Add(new ChatUserInfo { Connections = cxs });
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
|
|
@ -20,29 +19,10 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// GET: api/ContactsApi
|
||||
[HttpGet]
|
||||
public IEnumerable<ClientProviderInfo> GetClientProviderInfo()
|
||||
[HttpGet("{id}")]
|
||||
public ClientProviderInfo GetClientProviderInfo(string id)
|
||||
{
|
||||
return _context.ClientProviderInfo;
|
||||
}
|
||||
|
||||
// GET: api/ContactsApi/5
|
||||
[HttpGet("{id}", Name = "GetClientProviderInfo")]
|
||||
public IActionResult GetClientProviderInfo([FromRoute] string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
ClientProviderInfo clientProviderInfo = _context.ClientProviderInfo.Single(m => m.UserId == id);
|
||||
|
||||
if (clientProviderInfo == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(clientProviderInfo);
|
||||
return _context.ClientProviderInfo.FirstOrDefault(c=>c.UserId == id);
|
||||
}
|
||||
|
||||
// PUT: api/ContactsApi/5
|
||||
|
|
|
|||
15
Yavsc/ApiControllers/DjProfileApiController.cs
Normal file
15
Yavsc/ApiControllers/DjProfileApiController.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
using Models;
|
||||
using Models.Booking.Profiles;
|
||||
|
||||
public class DjProfileApiController : ProfileApiController<DjSettings>
|
||||
{
|
||||
public DjProfileApiController(ApplicationDbContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,6 @@ namespace Yavsc.Controllers
|
|||
[HttpPut("{id}")]
|
||||
public IActionResult PutEstimate(long id, [FromBody] Estimate estimate)
|
||||
{
|
||||
var valdate = DateTime.Now;
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
|
|
@ -90,7 +89,6 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
var entry = _context.Attach(estimate);
|
||||
estimate.ProviderValidationDate = valdate;
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
|
|
@ -107,7 +105,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
return Ok( new { Id = estimate.Id, LatestValidationDate = valdate });
|
||||
return Ok( new { Id = estimate.Id });
|
||||
}
|
||||
|
||||
// POST: api/Estimate
|
||||
|
|
@ -127,10 +125,15 @@ namespace Yavsc.Controllers
|
|||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
}
|
||||
var valdate = DateTime.Now;
|
||||
estimate.ProviderValidationDate = valdate;
|
||||
|
||||
if (estimate.CommandId!=null) {
|
||||
var query = _context.BookQueries.FirstOrDefault(q => q.Id == estimate.CommandId);
|
||||
if (query == null || query.PerformerId!= uid)
|
||||
throw new InvalidOperationException();
|
||||
query.ValidationDate = DateTime.Now;
|
||||
}
|
||||
_context.Estimates.Add(estimate);
|
||||
|
||||
|
||||
/* _context.AttachRange(estimate.Bill);
|
||||
_context.Attach(estimate);
|
||||
_context.Entry(estimate).State = EntityState.Added;
|
||||
|
|
@ -153,7 +156,7 @@ namespace Yavsc.Controllers
|
|||
throw;
|
||||
}
|
||||
}
|
||||
return Ok( new { Id = estimate.Id, Bill = estimate.Bill , LatestValidationDate = valdate });
|
||||
return Ok( new { Id = estimate.Id, Bill = estimate.Bill });
|
||||
}
|
||||
|
||||
// DELETE: api/Estimate/5
|
||||
|
|
|
|||
147
Yavsc/ApiControllers/MusicalPreferencesApiController.cs
Normal file
147
Yavsc/ApiControllers/MusicalPreferencesApiController.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Booking;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/museprefs")]
|
||||
public class MusicalPreferencesApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public MusicalPreferencesApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/MusicalPreferencesApi
|
||||
[HttpGet]
|
||||
public IEnumerable<MusicalPreference> GetMusicalPreferences()
|
||||
{
|
||||
return _context.MusicalPreferences;
|
||||
}
|
||||
|
||||
// GET: api/MusicalPreferencesApi/5
|
||||
[HttpGet("{id}", Name = "GetMusicalPreference")]
|
||||
public IActionResult GetMusicalPreference([FromRoute] string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
MusicalPreference musicalPreference = _context.MusicalPreferences.Single(m => m.OwnerProfileId == id);
|
||||
|
||||
if (musicalPreference == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(musicalPreference);
|
||||
}
|
||||
|
||||
// PUT: api/MusicalPreferencesApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutMusicalPreference(string id, [FromBody] MusicalPreference musicalPreference)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != musicalPreference.OwnerProfileId)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(musicalPreference).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!MusicalPreferenceExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/MusicalPreferencesApi
|
||||
[HttpPost]
|
||||
public IActionResult PostMusicalPreference([FromBody] MusicalPreference musicalPreference)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.MusicalPreferences.Add(musicalPreference);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (MusicalPreferenceExists(musicalPreference.OwnerProfileId))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetMusicalPreference", new { id = musicalPreference.OwnerProfileId }, musicalPreference);
|
||||
}
|
||||
|
||||
// DELETE: api/MusicalPreferencesApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteMusicalPreference(string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
MusicalPreference musicalPreference = _context.MusicalPreferences.Single(m => m.OwnerProfileId == id);
|
||||
if (musicalPreference == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.MusicalPreferences.Remove(musicalPreference);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(musicalPreference);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool MusicalPreferenceExists(string id)
|
||||
{
|
||||
return _context.MusicalPreferences.Count(e => e.OwnerProfileId == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Yavsc/ApiControllers/MusicalTendenciesApiController.cs
Normal file
147
Yavsc/ApiControllers/MusicalTendenciesApiController.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Booking;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/MusicalTendenciesApi")]
|
||||
public class MusicalTendenciesApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public MusicalTendenciesApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/MusicalTendenciesApi
|
||||
[HttpGet]
|
||||
public IEnumerable<MusicalTendency> GetMusicalTendency()
|
||||
{
|
||||
return _context.MusicalTendency;
|
||||
}
|
||||
|
||||
// GET: api/MusicalTendenciesApi/5
|
||||
[HttpGet("{id}", Name = "GetMusicalTendency")]
|
||||
public IActionResult GetMusicalTendency([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id);
|
||||
|
||||
if (musicalTendency == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(musicalTendency);
|
||||
}
|
||||
|
||||
// PUT: api/MusicalTendenciesApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutMusicalTendency(long id, [FromBody] MusicalTendency musicalTendency)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != musicalTendency.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(musicalTendency).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!MusicalTendencyExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/MusicalTendenciesApi
|
||||
[HttpPost]
|
||||
public IActionResult PostMusicalTendency([FromBody] MusicalTendency musicalTendency)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.MusicalTendency.Add(musicalTendency);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (MusicalTendencyExists(musicalTendency.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetMusicalTendency", new { id = musicalTendency.Id }, musicalTendency);
|
||||
}
|
||||
|
||||
// DELETE: api/MusicalTendenciesApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteMusicalTendency(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id);
|
||||
if (musicalTendency == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_context.MusicalTendency.Remove(musicalTendency);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(musicalTendency);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool MusicalTendencyExists(long id)
|
||||
{
|
||||
return _context.MusicalTendency.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,73 +2,55 @@ using System.IO;
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Microsoft.AspNet.Mvc.ViewComponents;
|
||||
using Microsoft.AspNet.Razor;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
using Models;
|
||||
using Helpers;
|
||||
using System.Linq;
|
||||
using Microsoft.Data.Entity;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
[Route("api/pdfestimate"), Authorize]
|
||||
public class PdfEstimateController : Controller
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
DefaultViewComponentHelper helper;
|
||||
IViewComponentDescriptorCollectionProvider provider;
|
||||
IViewComponentInvokerFactory factory;
|
||||
RazorEngineHost host;
|
||||
RazorTemplateEngine engine;
|
||||
IViewComponentSelector selector;
|
||||
private IStringLocalizer _localizer;
|
||||
private GoogleAuthSettings _googleSettings;
|
||||
private IGoogleCloudMessageSender _GCMSender;
|
||||
private IAuthorizationService authorizationService;
|
||||
|
||||
private ILogger logger;
|
||||
|
||||
public PdfEstimateController(
|
||||
IViewComponentDescriptorCollectionProvider provider,
|
||||
IViewComponentSelector selector,
|
||||
IViewComponentInvokerFactory factory,
|
||||
IAuthorizationService authorizationService,
|
||||
ILoggerFactory loggerFactory,
|
||||
ApplicationDbContext context)
|
||||
{
|
||||
|
||||
this.selector = selector;
|
||||
this.provider = provider;
|
||||
this.factory = factory;
|
||||
helper = new DefaultViewComponentHelper(provider, selector, factory);
|
||||
this.authorizationService = authorizationService;
|
||||
dbContext = context;
|
||||
|
||||
var language = new CSharpRazorCodeLanguage();
|
||||
host = new RazorEngineHost(language)
|
||||
{
|
||||
DefaultBaseClass = "RazorPage",
|
||||
DefaultClassName = "Estimate",
|
||||
DefaultNamespace = "Yavsc",
|
||||
};
|
||||
|
||||
// Everyone needs the System namespace, right?
|
||||
host.NamespaceImports.Add("System");
|
||||
engine = new RazorTemplateEngine(host);
|
||||
|
||||
|
||||
/*
|
||||
GeneratorResults razorResult =
|
||||
engine.GenerateCode(
|
||||
|
||||
) */
|
||||
logger = loggerFactory.CreateLogger<PdfEstimateController>();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("get/{id}", Name = "Get"), Authorize]
|
||||
public IActionResult Get(long id)
|
||||
public async Task<IActionResult> Get(long id)
|
||||
{
|
||||
var filename = $"estimate-{id}.pdf";
|
||||
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
var estimate = dbContext.Estimates.Include(
|
||||
e=>e.Query
|
||||
).FirstOrDefault(e=>e.Id == id);
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
// for example foo.bak
|
||||
FileName = filename,
|
||||
|
||||
// always prompt the user for downloading, set to true if you want
|
||||
// the browser to try to show the file inline
|
||||
Inline = false,
|
||||
};
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
var filename = $"estimate-{id}.pdf";
|
||||
|
||||
FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||
if (!fi.Exists) return Ok(new { Error = "Not generated" });
|
||||
|
|
@ -76,16 +58,104 @@ namespace Yavsc.ApiControllers
|
|||
}
|
||||
|
||||
[HttpGet("estimate-{id}.tex", Name = "GetTex"), Authorize]
|
||||
public IActionResult GetTex(long id)
|
||||
public async Task<IActionResult> GetTex(long id)
|
||||
{
|
||||
var estimate = dbContext.Estimates.Include(
|
||||
e=>e.Query
|
||||
).FirstOrDefault(e=>e.Id == id);
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
Response.ContentType = "text/x-tex";
|
||||
return ViewComponent("Estimate",new object[] { id, "LaTeX" });
|
||||
}
|
||||
|
||||
[HttpPost("gen/{id}")]
|
||||
public IActionResult GeneratePdf(long id)
|
||||
public async Task<IActionResult> GeneratePdf(long id)
|
||||
{
|
||||
var estimate = dbContext.Estimates.Include(
|
||||
e=>e.Query
|
||||
).FirstOrDefault(e=>e.Id == id);
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
return ViewComponent("Estimate",new object[] { id, "Pdf" } );
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("prosign/{id}")]
|
||||
public async Task<IActionResult> ProSign(long id)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var estimate = dbContext.Estimates.Include(
|
||||
e=>e.Query
|
||||
).FirstOrDefault(e=>e.Id == id && e.OwnerId == uid );
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
if (Request.Form.Files.Count!=1)
|
||||
return new BadRequestResult();
|
||||
User.ReceiveProSignature(id,Request.Form.Files[0],"pro");
|
||||
estimate.ProviderValidationDate = DateTime.Now;
|
||||
dbContext.SaveChanges();
|
||||
// Notify the client
|
||||
var yaev = new EstimationEvent(dbContext,estimate,_localizer);
|
||||
var regids = estimate.Client.Devices.Select(d => d.GCMRegistrationId);
|
||||
var grep = await _GCMSender.NotifyEstimateAsync(_googleSettings,regids,yaev);
|
||||
return Ok (new { ProviderValidationDate = estimate.ProviderValidationDate, GCMSent = grep.success });
|
||||
}
|
||||
|
||||
[HttpGet("prosign/{id}")]
|
||||
public async Task<IActionResult> GetProSign(long id)
|
||||
{
|
||||
// For authorization purpose
|
||||
var estimate = dbContext.Estimates.FirstOrDefault(e=>e.Id == id);
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
var filename = FileSystemHelpers.SignFileNameFormat("pro",id);
|
||||
FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||
if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" });
|
||||
return File(fi.OpenRead(), "application/x-pdf", filename); ;
|
||||
}
|
||||
|
||||
[HttpPost("clisign/{id}")]
|
||||
public async Task<IActionResult> CliSign(long id)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var estimate = dbContext.Estimates.Include( e=>e.Query
|
||||
).FirstOrDefault( e=> e.Id == id && e.Query.ClientId == uid );
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
if (Request.Form.Files.Count!=1)
|
||||
return new BadRequestResult();
|
||||
User.ReceiveProSignature(id,Request.Form.Files[0],"cli");
|
||||
estimate.ClientValidationDate = DateTime.Now;
|
||||
dbContext.SaveChanges();
|
||||
return Ok (new { ClientValidationDate = estimate.ClientValidationDate });
|
||||
}
|
||||
|
||||
[HttpGet("clisign/{id}")]
|
||||
public async Task<IActionResult> GetCliSign(long id)
|
||||
{
|
||||
// For authorization purpose
|
||||
var estimate = dbContext.Estimates.FirstOrDefault(e=>e.Id == id);
|
||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||
{
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
var filename = FileSystemHelpers.SignFileNameFormat("pro",id);
|
||||
FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||
if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" });
|
||||
return File(fi.OpenRead(), "application/x-pdf", filename); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Yavsc/ApiControllers/ProfileApiController.cs
Normal file
16
Yavsc/ApiControllers/ProfileApiController.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
using Models;
|
||||
[Produces("application/json"),Route("api/profile")]
|
||||
public abstract class ProfileApiController<T> : Controller
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
public ProfileApiController(ApplicationDbContext context)
|
||||
{
|
||||
dbContext = context;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue