Ejemplo n.º 1
0
        public async Task <IActionResult> Approve(int InvoiceId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var invoice = await _context.Invoices.SingleOrDefaultAsync(i => i.InvoiceId == InvoiceId);

                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    if (invoice != null)
                    {
                        invoice.Status      = InvoiceStatus.通过;
                        invoice.ApproveDate = DateTime.Now;
                        invoice.ApproverId  = user.Id;

                        var equipment = await _context.Equipments.SingleOrDefaultAsync(e => e.EquipmentId == invoice.EquipmentId);

                        if (equipment != null && equipment.Number > invoice.Number)
                        {
                            equipment.Number -= invoice.Number;
                            _context.Update(equipment);
                            _context.Update(invoice);
                        }
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(RedirectToAction("Approve"));
        }
 public async Task <IActionResult> Edit(Equipment equipment)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(equipment);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             throw;
         }
     }
     return(RedirectToAction("Store"));
 }