Exemplo n.º 1
0
        public ActionResult Add(TicketAddViewModel ticketVM)
        {
            if (ModelState.IsValid && ticketVM != null)
            {
                var userId = User.Identity.GetUserId();
                ApplicationUser user = this.Data.Users.All().FirstOrDefault(u => u.Id == userId);
                user.Points = user.Points + 1;
                Ticket ticket = new Ticket();
                ticket.Author = user;
                ticket.Category = this.Data.Categories.GetById(Convert.ToInt32(ticketVM.CategoryName));
                ticket.Priority = (Priority)Convert.ToInt32(ticketVM.PriorityName);
                ticket.ScreenshotURL = ticketVM.ScreenshotURL;
                ticket.Title = ticketVM.Title;
                ticket.Description = ticketVM.Description;

                this.Data.Tickets.Add(ticket);
                this.Data.SaveChanges();

                return RedirectToAction("TicketsList");
            }

            ticketVM.Categories = this.Data.Categories.All().ToList().Select(cat => new SelectListItem() { Text = cat.Name, Value = cat.Id.ToString() });
            ticketVM.Priorities = LoadPrioritiesFromEnumeration();

            return View(ticketVM);
        }
Exemplo n.º 2
0
        public ActionResult Add()
        {
            var model = new TicketAddViewModel();
            model.Categories = this.Data.Categories.All().ToList().Select(cat => new SelectListItem() { Text = cat.Name, Value = cat.Id.ToString() });
            model.Priorities = LoadPrioritiesFromEnumeration();
            model.PriorityName = "1";

            return View(model);
        }