示例#1
0
 public async Task <IActionResult> Edit(int id, PrinterAccessory accessory)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(accessory);
             //TODO: Notify registry about this update
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!AccessoryExists(accessory.PrinterAccessoryId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(RedirectToAction(nameof(Index)));
 }
示例#2
0
        public async Task <IActionResult> Create(PrinterEvent printerEvent)
        {
            if (printerEvent.PrinterAccessory == null)
            {
                return(null);
            }
            printerEvent.Date    = DateTime.Now;
            printerEvent.Printer = _context.Printers.Find(printerEvent.Printer.PrinterId);

            if (printerEvent.EventType == PrinterEventType.ZgloszenieAwarii)
            {
                printerEvent.PrinterAccessory = _context.PrinterAccessories.Find(1);
            }
            else
            {
                PrinterAccessory accessory = _context.PrinterAccessories.Find(printerEvent.PrinterAccessory.PrinterAccessoryId);
                printerEvent.PrinterAccessory = accessory;

                var accessoryToModify = _context.Entry(accessory);
                accessoryToModify.Entity.Availability = accessoryToModify.Entity.Availability - 1;
                accessoryToModify.State = EntityState.Modified;
            }

            _context.PrinterEvents.Add(printerEvent);
            await _context.SaveChangesAsync();

            return(ViewComponent("PrinterEvents", new { printerId = printerEvent.Printer.PrinterId }));
        }