public ActionResult AddTicket(AddTicketModel model) { if (ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var ticket = new Ticket() { AuthorId = userId, CategoryId = model.Category, Title = model.Title, Priority = ConvertStringToPriority(model.Priority), Description = model.Description, ScreenshotUrl = model.ScreenshotUrl }; this.Db.Tickets.Add(ticket); var user = this.Db.Users.All().FirstOrDefault(u => u.Id == userId); user.Points += 1; this.Db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Categories = this.Db.Categories.All().Select(x => new { Name = x.Name, Id = x.Id }); ViewBag.Priorities = Enum.GetNames(typeof(Priority)); return(View()); }
public AddTicketModel prepreateAddTicketModel(int eventId) { AddTicketModel addTicketModel = new AddTicketModel(); addTicketModel.EventId = eventId; List <Ticket> tickets = tRepository.getTicketsByEvent(eventId); foreach (var ticket in tickets) { TicketInventory ticketInventory = tiRepository.getTicketInventoryByTicket(ticket.Id); TicketViewModel ticketViewModel = new TicketViewModel() { Id = ticket.Id, Name = ticket.Name, Price = ticket.Price, DiscountPrice = ticket.DiscountPrice.HasValue?ticket.DiscountPrice.Value:0m, StockQuantity = ticketInventory.StockQuantity.HasValue?ticketInventory.StockQuantity.Value:0, ReservedQuantity = ticketInventory.ReservedQuantity.HasValue?ticketInventory.ReservedQuantity.Value:0 }; addTicketModel.Tickets.Add(ticketViewModel); } return(addTicketModel); }
public ActionResult Create4(AddTicketModel addTicketModel) { Ticket ticket = new Ticket() { Name = addTicketModel.Name, Price = addTicketModel.Price, DiscountPrice = addTicketModel.DiscountPrice, IdEvent = addTicketModel.EventId }; TicketInventory ticketInventory = new TicketInventory() { ReservedQuantity = 0, StockQuantity = addTicketModel.Quantity }; tFactory.saveTicketWithInventory(ticket, ticketInventory); return(View(tFactory.prepreateAddTicketModel(addTicketModel.EventId))); }
public IActionResult AddTicket() { var flights = _flightService.GetAll(); var ticketTypes = _unitOfWork.TicketTypeRepository.GetAll(); var typesDTO = new List <TicketTypeDTO>(); foreach (var t in ticketTypes) { var type = new TicketTypeDTO { Id = t.Id, TypeName = t.TypeName }; typesDTO.Add(type); } var addTicketModel = new AddTicketModel() { Flights = flights, Types = typesDTO }; return(View(addTicketModel)); }