Ejemplo n.º 1
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 }));
        }
Ejemplo n.º 2
0
        public IActionResult CreateByCustId(int id)
        {
            //The DeviceEditViewModel stores a Ticket, a Customer and TicketID and CustomerID
            //On get Customer is populated, on Post Ticket is populated, the customer will
            //have to be retrieved again if needed on post.

            Customer cust = context.Customers.Find(id);

            var model = new NewDeviceCreateViewModel
            {
                TicketNumber      = context.Tickets.GetLatestTicketNum() + 1,
                CustomerId        = id,
                CustomerFirstName = cust.FirstName,
                CustomerLastName  = cust.LastName
            };

            return(View(model));
        }