public ActionResult GetAmountOfTickets(DatesViewModel dates) { var groupByTicketTypes = new TicketTypeViewModel() { TicketZonesWithAmount = (from tr in ctx.Transactions join t in ctx.Tickets on tr.Id equals t.Transaction.Id join c in ctx.TransportCards on t.Card.Id equals c.Id where DateTime.Compare(tr.Date, dates.StartTime) >= 0 && DateTime.Compare(tr.Date, dates.EndTime) <= 0 group new { t, c, tr } by c.CardType into types select new TicketTypeViewModel { CardType = types.Key, AmountOfTickets = types.Count() } ) .Union(from tr in ctx.Transactions join t in ctx.Tickets on tr.Id equals t.Transaction.Id where t.Card == null && DateTime.Compare(tr.Date, dates.StartTime) >= 0 && DateTime.Compare(tr.Date, dates.EndTime) <= 0 group new { t, tr } by t.Card into types select new TicketTypeViewModel { CardType = CardType.Paper, AmountOfTickets = types.Count() } ).ToList() }; return(View(groupByTicketTypes)); }
public ActionResult EditTicketTypePost(TicketTypeViewModel model) { if (!this.services.Authorizer.Authorize(Permissions.BasicDataPermission)) { return(new HttpUnauthorizedResult()); } if (!this.ModelState.IsValid) { return(this.View("EditTicketType", model)); } var ticketType = this.ticketTypeRepository.Table.FirstOrDefault(c => c.Id == model.TicketTypeId); if (ticketType == null) { this.ModelState.AddModelError("Id", this.T("There is no ticketType with the given Id").ToString()); return(this.View("EditTicketType", model)); } ticketType.Name = model.Name; ticketType.OrderId = model.OrderId; this.ticketTypeRepository.Flush(); this.basicDataService.ClearCache(); return(RedirectToAction("TicketTypes")); }
public async Task AddTicketTypeAsync(TicketTypeViewModel model) { var ticketType = _mapper.Map <TicketType>(model); _context.TicketTypes.Add(ticketType); await _context.SaveChangesAsync(); }
public async Task <ActionResult <Response <string> > > Put(int id, [FromBody] TicketTypeViewModel model) { var updateResult = await _ticketTypeService.UpdateTicketTypeAsync(id, model); if (updateResult.Success == false) { return(BadRequest(updateResult)); } return(Ok(updateResult)); }
public ActionResult EditTicketType(int id) { if (!this.services.Authorizer.Authorize(Permissions.BasicDataPermission)) { return(new HttpUnauthorizedResult()); } var ticketType = this.ticketTypeRepository.Table.FirstOrDefault(c => c.Id == id); var model = new TicketTypeViewModel { TicketTypeId = ticketType.Id, Name = ticketType.Name, OrderId = ticketType.OrderId }; return(this.View(model)); }
public async Task <Response <string> > UpdateTicketTypeAsync(int id, TicketTypeViewModel model) { var ticketType = await _context.TicketTypes.FindAsync(id); if (ticketType == null) { return(new Response <string> { Success = false, Message = "There is no such type of ticket" }); } _mapper.Map(model, ticketType); await _context.SaveChangesAsync(); return(new Response <string> { Success = true, Message = "Type of ticket was succesfully updated" }); }
public ActionResult CreateTicketTypePost(TicketTypeViewModel model) { if (!this.services.Authorizer.Authorize(Permissions.BasicDataPermission)) { return(new HttpUnauthorizedResult()); } if (!this.ModelState.IsValid) { return(this.View("CreateTicketType", model)); } TicketTypeRecord ticketType = new TicketTypeRecord(); this.ticketTypeRepository.Create(ticketType); ticketType.Name = model.Name; ticketType.OrderId = model.OrderId; this.ticketTypeRepository.Flush(); this.basicDataService.ClearCache(); return(RedirectToAction("TicketTypes")); }
public async Task <ActionResult> Post([FromBody] TicketTypeViewModel model) { await _ticketTypeService.AddTicketTypeAsync(model); return(Ok()); }