public IActionResult Service(NewLogServiceViewModel model)
        {
            //check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.TicketStatus == TicketStatus.New)
            {
                model.TicketStatus = TicketStatus.InProgress;
            }
            var ticket = context.Tickets.Find(model.TicketId);
            Log log    = new Log
            {
                UserCreated  = User.FindFirst(ClaimTypes.Name).Value.ToString(),
                TicketId     = model.TicketId,
                DateCreated  = DateTime.Now,
                Notes        = model.LogNotes,
                EventId      = model.SelectedEventId,
                TicketStatus = model.TicketStatus
            };

            context.Add(log);
            //update the database with any changes that were made to the ticketstatus
            context.SaveChanges();
            return(RedirectToAction("Index", "Ticket"));
        }
        public TicketConfirmationModel CreateTicket(TicketCreatorInfo info)
        {
            Ticket ticket = new Ticket
            {
                DeviceId = info.DeviceId,
                //Gets a string representation of the ChipsUser currently logged in
                CheckInUserId = info.UserName,
                CheckInDate   = DateTime.Now,
                NeedsBackup   = info.NeedsBackup,
                Status        = TicketStatus.New,
                TicketNumber  = context.Tickets.GetLatestTicketNum() + 1
            };

            //Save the new Ticket
            context.Add(ticket);
            context.SaveChanges();
            // TODO don't commit ticket until initial log has been created -- if log creation fails an incomplete ticket is created
            //Create a log entry with the newly created Ticket.Id as a foreign key
            Log log = new Log
            {
                EventId = (int)EventEnum.CheckIn,
                // TODO get event id dynamically from db
                UserCreated = info.UserName,
                TicketId    = ticket.Id,
                DateCreated = DateTime.Now,
                Notes       = info.Notes
            };

            //Add new Log
            context.Add(log);
            context.SaveChanges();
            //Create a new entry in the update table with a guid for the Primary Key and
            //a foreign key from the Ticket
            TicketProgress update = new TicketProgress
            {
                Id       = new Guid(),
                TicketId = ticket.Id
            };

            //Save Changes
            _updates.Add(update);
            _updates.Commit();
            return(new TicketConfirmationModel
            {
                ticketId = ticket.Id,
                deviceId = info.DeviceId,
                customerId = info.CustomerId,
                updateId = update.Id
            });
        }
Beispiel #3
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 }));
        }