fixes prosign

main
Paul Schneider 9 years ago
parent c7759c7558
commit 92307ec59b
1 changed files with 17 additions and 8 deletions

@ -32,14 +32,15 @@ namespace Yavsc.ApiControllers
public PdfEstimateController( public PdfEstimateController(
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
ApplicationDbContext context) IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR,
ApplicationDbContext context)
{ {
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
dbContext = context; dbContext = context;
logger = loggerFactory.CreateLogger<PdfEstimateController>(); logger = loggerFactory.CreateLogger<PdfEstimateController>();
this._localizer = SR;
} }
[HttpGet("get/{id}", Name = "Get"), Authorize] [HttpGet("get/{id}", Name = "Get"), Authorize]
public async Task<IActionResult> Get(long id) public async Task<IActionResult> Get(long id)
{ {
@ -89,10 +90,12 @@ namespace Yavsc.ApiControllers
[HttpPost("prosign/{id}")] [HttpPost("prosign/{id}")]
public async Task<IActionResult> ProSign(long id) public async Task<IActionResult> ProSign(long id)
{ {
var uid = User.GetUserId(); var estimate = dbContext.Estimates.
var estimate = dbContext.Estimates.Include( Include(e=>e.Client).Include(e=>e.Client.Devices)
e=>e.Query .Include(e=>e.Bill).Include(e=>e.Owner).Include(e=>e.Owner.Performer)
).FirstOrDefault(e=>e.Id == id && e.OwnerId == uid ); .FirstOrDefault(e=>e.Id == id);
if (estimate == null)
return new BadRequestResult();
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
{ {
return new ChallengeResult(); return new ChallengeResult();
@ -103,9 +106,14 @@ namespace Yavsc.ApiControllers
estimate.ProviderValidationDate = DateTime.Now; estimate.ProviderValidationDate = DateTime.Now;
dbContext.SaveChanges(); dbContext.SaveChanges();
// Notify the client // Notify the client
var locstr = _localizer["EstimationMessageToClient"];
var yaev = new EstimationEvent(dbContext,estimate,_localizer); var yaev = new EstimationEvent(dbContext,estimate,_localizer);
var regids = estimate.Client.Devices.Select(d => d.GCMRegistrationId);
var regids = estimate.Client.Devices.Select(d => d.GCMRegistrationId).ToArray();
logger.LogWarning($"new regids: {regids}");
var grep = await _GCMSender.NotifyEstimateAsync(_googleSettings,regids,yaev); var grep = await _GCMSender.NotifyEstimateAsync(_googleSettings,regids,yaev);
logger.LogWarning($"grep: {grep}");
return Ok (new { ProviderValidationDate = estimate.ProviderValidationDate, GCMSent = grep.success }); return Ok (new { ProviderValidationDate = estimate.ProviderValidationDate, GCMSent = grep.success });
} }
@ -130,7 +138,8 @@ namespace Yavsc.ApiControllers
{ {
var uid = User.GetUserId(); var uid = User.GetUserId();
var estimate = dbContext.Estimates.Include( e=>e.Query var estimate = dbContext.Estimates.Include( e=>e.Query
).FirstOrDefault( e=> e.Id == id && e.Query.ClientId == uid ); ).Include(e=>e.Owner).Include(e=>e.Owner.Performer).Include(e=>e.Client)
.FirstOrDefault( e=> e.Id == id && e.Query.ClientId == uid );
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
{ {
return new ChallengeResult(); return new ChallengeResult();

Loading…