public ActionResult Create([Bind(Include = "ProjectId,TicketTypeId,TicketPriorityId,Title,Description")] Ticket ticket, HttpPostedFileBase[] files)
        {
            if (ModelState.IsValid)
            {
                List <Tuple <string, string, string> > fileUploadResult = FileUploadHelper.UploadMultipleFiles(files);
                foreach (Tuple <string, string, string> upload in fileUploadResult)
                {
                    TicketAttachment ticketAttachment = new TicketAttachment();
                    ticketAttachment.Title         = upload.Item1;
                    ticketAttachment.AttachmentUrl = upload.Item2;
                    ticketAttachment.Description   = upload.Item3;
                    ticketAttachment.Created       = DateTime.Now;
                    ticketAttachment.UserId        = User.Identity.GetUserId();
                    db.TicketAttachments.Add(ticketAttachment);
                    ticket.TicketAttachments.Add(ticketAttachment);
                    HistoryHelper.AnyAttachment(ticket, ticketAttachment, true);
                }
                ticket.TicketStatusId = db.TicketStatuses.FirstOrDefault(t => t.Name == "New/UnAssigned").Id;
                ticket.OwnerUserId    = User.Identity.GetUserId();
                ticket.Created        = DateTime.Now;
                db.Tickets.Add(ticket);
                db.SaveChanges();
                HistoryHelper.AnyCreated(ticket);
                return(RedirectToAction("MyIndex"));
            }

            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
            //ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            return(View(ticket));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,ProjectId,TicketTypeId,TicketStatusId,TicketPriorityId,OwnerUserId,AssignedToUserId,Title,Description,Created,Updated")] Ticket ticket, HttpPostedFileBase[] files)
        {
            if (ModelState.IsValid)
            {
                List <Tuple <string, string, string> > fileUploadResult = FileUploadHelper.UploadMultipleFiles(files);
                foreach (Tuple <string, string, string> upload in fileUploadResult)
                {
                    TicketAttachment ticketAttachment = new TicketAttachment();
                    ticketAttachment.Title         = upload.Item1;
                    ticketAttachment.AttachmentUrl = upload.Item2;
                    ticketAttachment.Description   = upload.Item3;
                    ticketAttachment.Created       = DateTime.Now;
                    ticketAttachment.UserId        = User.Identity.GetUserId();
                    ticketAttachment.TicketId      = ticket.Id;
                    db.TicketAttachments.Add(ticketAttachment);
                    ticket.TicketAttachments.Add(ticketAttachment);
                    HistoryHelper.AnyAttachment(ticket, ticketAttachment, true);
                }

                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);

                ticket.Updated         = DateTime.Now;
                db.Entry(ticket).State = EntityState.Modified;
                db.SaveChanges();
                var newTicket   = db.Tickets.Where(n => n.Id == ticket.Id).Include(n => n.TicketPriority).Include(n => n.TicketStatus).Include(n => n.TicketType).FirstOrDefault();
                var callbackUrl = Url.Action("Details", "Tickets", new { id = ticket.Id }, protocol: Request.Url.Scheme);
                await NotificationHelper.ManageNotifications(oldTicket, newTicket, callbackUrl, false);

                HistoryHelper.AnyChanges(oldTicket, ticket);
                return(RedirectToAction("MyIndex"));
            }
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            return(View(ticket));
        }