Exemplo n.º 1
0
        public IActionResult CreateByExistingDeviceId(DeviceEditViewModel model)
        {
            //Get Ticket Number again and check ModelState
            model.Ticket.TicketNumber = context.Tickets.GetLatestTicketNum() + 1;
            if (!ModelState.IsValid)
            {
                model.Customer = context.Customers.Find(model.CustomerId);
                return(View(model));
            }
            //get the device and create a new ticket from the device
            var device = context.Devices.Find(model.Id);
            TicketConfirmationModel tcModel = _ticketCreator.CreateTicket(new TicketCreatorInfo
            {
                DeviceId    = device.Id,
                CustomerId  = device.CustomerId,
                NeedsBackup = model.Ticket.NeedsBackup,
                Notes       = model.Log.Notes,
                UserName    = User.FindFirst(ClaimTypes.Name).Value.ToString()
            });

            return(RedirectToAction("Confirmation", "Ticket", new
            {
                ticketId = tcModel.ticketId,
                deviceId = tcModel.deviceId,
                customerId = tcModel.customerId,
                updateId = tcModel.updateId
            }));
        }
Exemplo n.º 2
0
        public IActionResult CreateByCustId(NewDeviceCreateViewModel model)
        {
            //Check if Model State is Valid
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //Create a new device using the Customer ID and form data
            Device device = new Device
            {
                CustomerId      = model.CustomerId,
                Make            = model.Make,
                ModelNumber     = model.ModelNumber,
                OperatingSystem = model.OperatingSystem,
                Password        = model.Password,
                Serviced        = model.Serviced
            };

            //Save the new device
            context.Add(device);
            context.SaveChanges();
            TicketConfirmationModel tcModel = _ticketCreator.CreateTicket(new TicketCreatorInfo
            {
                DeviceId    = device.Id,
                CustomerId  = model.CustomerId,
                NeedsBackup = model.TicketNeedsBackup,
                Notes       = model.LogNotes,
                UserName    = User.FindFirst(ClaimTypes.Name).Value.ToString()
            });

            return(RedirectToAction("Confirmation", "Ticket", new { ticketId = tcModel.ticketId,
                                                                    deviceId = tcModel.deviceId,
                                                                    customerId = tcModel.customerId,
                                                                    updateId = tcModel.updateId }));
        }