public async Task UpdateBill(OnlineBillDTO onlineBill) { if (onlineBill == null) { throw new ArgumentNullException(nameof(onlineBill)); } var order = await DbContext.OnlineOrder .Where(o => o.OrderGuid == onlineBill.Guid) .Include(o => o.AssignUser) .Include(o => o.Stage) .SingleOrDefaultAsync(); if (order == null) { throw new BussinessException($"Cant find order of {onlineBill.Guid}"); } //Only allow when WaitForOnlineBill if (order.StageId != (int)StageEnum.WaitForOnlineBill) { throw new BussinessException($"Order is not ready for bill number, current stage: {order.Stage.Stage}"); } order.OrderNumber = onlineBill.OnlineBill; order.StageId = (int)StageEnum.Completed; await DbContext.SaveChangesAsync(); _mail.MailOnlineBillAvailable(order, order.AssignUser.Email, onlineBill.OnlineBill, null); }
public async Task <IActionResult> UpdateBill([FromBody] OnlineBillDTO onlineBill) { if (!ModelState.IsValid) { return(BadRequest()); } //Check auth if (!_apiAuth.Check(onlineBill.Signature, onlineBill.Guid)) { return(Unauthorized()); } try { await _service.UpdateBill(onlineBill); return(Ok()); } catch (BussinessException ex) { _logger.LogDebug(ex.Message); return(BadRequest(ex.Message)); } }