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 })); }
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))); }
public async Task <IActionResult> Create([Bind("PrinterId,IP,Localisation,SerialNumber,Photo,Info,Person,Status,PrinterType")] Printer printer) { printer.PrinterType = _context .PrinterTypes .SingleOrDefault(a => a.PrinterTypeId == printer.PrinterType.PrinterTypeId); if (ModelState.IsValid) { _context.Add(printer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } populatePrinterTypeDropDown(); return(View(printer)); }