public void CreateNewTicket(TicketInputModel model) { var cmd = new CreateTicketCommand(model.Title, model.Description, model.Status, model.Priority, model.Type, model.DueDate, model.ResolutionComments, model.RequestorLoginName, model.AssignedToLoginName, model.Category); _bus.Send(cmd); }
public async Task CheckSettingOfTicketProperties() { this.SeedDatabase(); var model = new TicketInputModel { Row = 1, Seat = this.firstSeat.Id, Price = 20, TimeSlot = TimeSlot.Morning.ToString(), TicketType = TicketType.ForChildren.ToString(), Quantity = 1, MovieProjectionTime = this.firstMovieProjection.Date, }; await this.ticketsService.BuyAsync(model, this.firstMovieProjection.Id); var ticket = await this.ticketsRepository.All().FirstOrDefaultAsync(); Assert.Equal(1, ticket.Row); Assert.Equal(this.firstSeat.Id, ticket.Seat); Assert.Equal(20, ticket.Price); Assert.Equal("Afternoon", ticket.TimeSlot.ToString()); Assert.Equal("ForChildren", ticket.TicketType.ToString()); Assert.Equal(1, ticket.Quantity); }
public IActionResult CreateTicket(TicketInputModel model) { model.AssignerId = User.FindFirst("sub").Value; if (!TryValidateModel(model)) { throw new Exception("Поля заполнены неверно!"); } if (_employeeService.GetEmployee(model.AssigneeId) == null) { throw new Exception($"Пользователь с id {model.AssigneeId} не найден"); } if (_employeeService.GetEmployee(model.AssignerId) == null) { throw new Exception($"Пользователь с id {model.AssignerId} не найден"); } try { _ticketsService.AddOrUpdateTicket(model); return(RedirectToAction("Index")); } catch (Exception ex) { throw HelperMethods.LogAndThrow("При попытке добавления тикета произошла ошибка", ex, _logger); } }
public async Task CheckIfBuyAsyncWorksCorrectlyWithMorningTimeSlot() { this.SeedDatabase(); var dateAsString = "30/09/2020 09:30:00"; var newDate = DateTime.ParseExact(dateAsString, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); this.firstMovieProjection.Date = newDate; var model = new TicketInputModel { Row = this.firstTicket.Row, Seat = this.firstSeat.Id, Price = this.firstTicket.Price, TicketType = this.firstTicket.TicketType.ToString(), Quantity = this.firstTicket.Quantity, MovieProjectionTime = this.firstMovieProjection.Date, }; await this.ticketsService.BuyAsync(model, this.firstMovieProjection.Id); var ticket = await this.ticketsRepository.All().FirstOrDefaultAsync(); Assert.Equal("Morning", ticket.TimeSlot.ToString()); }
public async Task CheckIfBuyingTicketReturnsViewModel() { this.SeedDatabase(); var ticket = new TicketInputModel { Row = this.firstTicket.Row, Seat = this.firstTicket.Seat, Price = this.firstTicket.Price, TimeSlot = this.firstTicket.TimeSlot.ToString(), TicketType = this.firstTicket.TicketType.ToString(), Quantity = this.firstTicket.Quantity, MovieProjectionTime = this.firstMovieProjection.Date, }; var viewModel = await this.ticketsService.BuyAsync(ticket, this.firstMovieProjection.Id); var dbEntry = await this.ticketsRepository.All().FirstOrDefaultAsync(); Assert.Equal(dbEntry.Row, viewModel.Row); Assert.Equal(dbEntry.Seat, viewModel.Seat); Assert.Equal(dbEntry.Price, viewModel.Price); Assert.Equal(dbEntry.TimeSlot, viewModel.TimeSlot); Assert.Equal(dbEntry.TicketType, viewModel.TicketType); Assert.Equal(dbEntry.Quantity, viewModel.Quantity); }
public Ticket AddOrUpdateTicket(TicketInputModel ticket) { if ((ticket.Id ?? 0) == 0) { return(AddTicket(ticket)); } return(UpdateTicket(ticket)); }
public IHttpActionResult CreateTicket(TicketInputModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _ticketsService.CreateNewTicket(model); return(Ok()); }
private Ticket AddTicket(TicketInputModel ticket) { var result = new Ticket { AssigneeId = ticket.AssigneeId, AssignerId = ticket.AssignerId, Description = ticket.Description, Name = ticket.Name, Priority = ticket.Priority, State = ticket.State }; _context.Add(result); _context.SaveChangesAsync().GetAwaiter(); return(result); }
///<summary> /// Updates information about users' tickets with selected parameters ///</summary> ///<param name="userId">Id of the user</param> ///<param name="input">Ticket information</param> ///<param name="projection">Projection information</param> ///<param name="DateTime">Ticket time paramater</param> ///<returns>Mapped instance of type <see cref="ProjectionTicket"/></returns> public ProjectionTicket MapToProjectionTicket(string userId, TicketInputModel input, FilmProjection projection, DateTime timeStamp) { return(new ProjectionTicket { ProjectionId = projection.Id, Seat = input.Seat, Type = input.TicketType, Price = (double)projection.TicketPrices.GetType(). GetProperty($"{input.TicketType.ToString()}Price"). GetValue(projection.TicketPrices), HolderId = userId, ReservedOn = timeStamp }); }
public IActionResult EditTicket(TicketInputModel model) { model.AssignerId = User.FindFirst("sub").Value; if (!TryValidateModel(model)) { throw new Exception("Поля заполнены неверно!"); } try { _ticketsService.AddOrUpdateTicket(model); return(RedirectToAction("Index")); } catch (Exception ex) { throw HelperMethods.LogAndThrow($"При попытке обновления тикета произошла ошибка:", ex, _logger); } }
private Ticket UpdateTicket(TicketInputModel ticket) { var result = _context.Tickets.Where(t => t.Id == ticket.Id).FirstOrDefaultAsync().Result; if (result is null) { throw new InvalidOperationException($"Задача с идентификатором {ticket.Id} не найдена!"); } result.AssigneeId = ticket.AssigneeId; result.AssignerId = ticket.AssignerId; result.Description = ticket.Description; result.Name = ticket.Name; result.Priority = ticket.Priority; result.State = ticket.State; _context.Entry(result).State = EntityState.Modified; _context.SaveChanges(); return(result); }
public async Task CheckAddingTicketWithInvalidTicketType() { this.SeedDatabase(); var ticket = new TicketInputModel { Row = 1, Seat = this.firstSeat.Id, Price = 20, TimeSlot = TimeSlot.Morning.ToString(), TicketType = "Invalid type", Quantity = 1, MovieProjectionTime = this.firstMovieProjection.Date, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.ticketsService.BuyAsync(ticket, this.firstMovieProjection.Id)); Assert.Equal(string.Format(ExceptionMessages.InvalidTicketType, ticket.TicketType), exception.Message); }
public async Task CheckAddingTicketWithMissingSeat() { this.SeedDatabase(); var ticket = new TicketInputModel { Row = 3, Seat = 3, Price = 20, TimeSlot = TimeSlot.Morning.ToString(), TicketType = TicketType.ForChildren.ToString(), Quantity = 1, MovieProjectionTime = this.firstMovieProjection.Date, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.ticketsService.BuyAsync(ticket, this.firstMovieProjection.Id)); Assert.Equal(string.Format(ExceptionMessages.SeatNotFound, ticket.Seat), exception.Message); }
public async Task CheckIfBuyAsyncWorksCorrectly() { this.SeedDatabase(); var model = new TicketInputModel { Row = 1, Seat = this.firstSeat.Id, Price = 15, TimeSlot = TimeSlot.Afternoon.ToString(), TicketType = TicketType.Regular.ToString(), Quantity = 2, MovieProjectionTime = this.firstMovieProjection.Date, }; await this.ticketsService.BuyAsync(model, this.firstMovieProjection.Id); var count = await this.ticketsRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckAddingAlreadyExistingTicket() { this.SeedDatabase(); await this.SeedTickets(); var ticket = new TicketInputModel { Row = this.firstTicket.Row, Seat = this.firstTicket.Seat, Price = this.firstTicket.Price, TimeSlot = this.firstTicket.TimeSlot.ToString(), TicketType = this.firstTicket.TicketType.ToString(), Quantity = this.firstTicket.Quantity, MovieProjectionTime = this.firstMovieProjection.Date, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.ticketsService.BuyAsync(ticket, this.firstMovieProjection.Id)); Assert.Equal(string.Format(ExceptionMessages.TicketAlreadyExists, ticket.Row, ticket.Seat), exception.Message); }
public async Task CheckAddingTicketWithSoldSeat() { this.SeedDatabase(); this.firstSeat.IsSold = true; var ticket = new TicketInputModel { Row = 1, Seat = this.firstSeat.Id, Price = 10, TimeSlot = TimeSlot.Еvening.ToString(), TicketType = TicketType.Retired.ToString(), Quantity = 2, MovieProjectionTime = this.firstMovieProjection.Date, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.ticketsService.BuyAsync(ticket, this.firstMovieProjection.Id)); Assert.Equal(string.Format(ExceptionMessages.SeatSoldError, this.firstSeat.Id), exception.Message); }
public async Task <TicketDetailsViewModel> BuyAsync(TicketInputModel ticketInputModel, int movieProjectionId) { if (!Enum.TryParse(ticketInputModel.TicketType, true, out TicketType ticketType)) { throw new ArgumentException( string.Format(ExceptionMessages.InvalidTicketType, ticketInputModel.TicketType)); } var movieProjection = await this.movieProjectionsRepository .All() .FirstOrDefaultAsync(x => x.Id == movieProjectionId); if (movieProjection == null) { throw new ArgumentException( string.Format(ExceptionMessages.MovieProjectionNotFound, movieProjectionId)); } var seat = await this.seatsRepository .All() .FirstOrDefaultAsync(x => x.RowNumber == ticketInputModel.Row && x.Number == ticketInputModel.Seat && x.HallId == movieProjection.HallId); if (seat == null) { throw new ArgumentException( string.Format(ExceptionMessages.SeatNotFound, ticketInputModel.Seat)); } if (seat.IsSold) { throw new ArgumentException( string.Format(ExceptionMessages.SeatSoldError, seat.Id)); } var ticket = new Ticket { Row = ticketInputModel.Row, Seat = ticketInputModel.Seat, Price = ticketInputModel.Price, TicketType = ticketType, Quantity = ticketInputModel.Quantity, }; bool doesTicketExist = await this.ticketsRepository .All() .AnyAsync(x => x.Row == ticket.Row && x.Seat == ticket.Seat); if (doesTicketExist) { throw new ArgumentException( string.Format(ExceptionMessages.TicketAlreadyExists, ticket.Row, ticket.Seat)); } var movieProjectionHour = ticketInputModel.MovieProjectionTime.TimeOfDay.TotalHours; this.SetTimeSlot(ticket, movieProjectionHour); seat.IsAvailable = false; seat.IsSold = true; this.seatsRepository.Update(seat); await this.seatsRepository.SaveChangesAsync(); await this.ticketsRepository.AddAsync(ticket); await this.ticketsRepository.SaveChangesAsync(); var viewModel = await this.GetViewModelByIdAsync <TicketDetailsViewModel>(ticket.Id); return(viewModel); }