Example #1
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 }));
        }
Example #2
0
 protected virtual void End() => PrinterEvent?.Invoke(this, new PrinterEventArgs(this, "Printing ended"));
Example #3
0
 protected virtual void Start() => PrinterEvent?.Invoke(this, new PrinterEventArgs(this, "Printing started"));