Esempio n. 1
0
 public ActionResult Create(int?Id)
 {
     ViewBag.PriorityId = new SelectList(EnumsController.EnumToDropDownList(typeof(Priority)), "Value", "Text");
     ViewBag.CategoryId = new SelectList(this.Data.Categories.All(), "Id", "Name");
     ViewBag.TicketId   = Id;
     return(View());
 }
Esempio n. 2
0
        public ActionResult Create(TicketCreateViewModel ticket)
        {
            ViewBag.PriorityId = new SelectList(EnumsController.EnumToDropDownList(typeof(Priority)), "Value", "Text");
            ViewBag.CategoryId = new SelectList(this.Data.Categories.All(), "Id", "Name");

            if (User.Identity.IsAuthenticated && ModelState.IsValid)
            {
                using (TransactionScope tsTransScope = new TransactionScope())
                {
                    Ticket parentTicket  = null;
                    var    currentUserId = User.Identity.GetUserId();

                    var currentUser = this.Data.ApplicationUsers.All().FirstOrDefault(u => u.Id == currentUserId);
                    currentUser.Points = currentUser.Points + 1;
                    if (ticket.Ticket_Id != 0)
                    {
                        parentTicket = this.Data.Tickets.GetById(ticket.Ticket_Id);
                        // parentTicket.Add(parentTicketObjet);
                    }

                    var newTicket = new Ticket()
                    {
                        AuthorId      = currentUserId,
                        CategoryId    = ticket.CategoryId,
                        Description   = HttpUtility.HtmlEncode(ticket.Description),
                        Priority      = (Priority)ticket.PriorityId,
                        ScreenshotUrl = ticket.ScreenshotUrl,
                        Title         = ticket.Title,
                        Tickets       = parentTicket,
                        CreateDate    = DateTime.UtcNow
                    };

                    this.Data.Tickets.Add(newTicket);
                    this.Data.SaveChanges();
                    tsTransScope.Complete();
                }

                return(RedirectToAction("TicketsList"));
            }

            return(View());
        }