public ActionResult Create(SeatDto dto) { if (!ModelState.IsValid) { TempData["error"] = "Check your input."; return(RedirectToAction(nameof(Create))); } try { executor.ExecuteCommand(addSeat, dto); return(RedirectToAction(nameof(Index))); } catch (EntityNotAllowedException) { return(RedirectToAction("PageNotFound", "Redirections")); } catch (EntityAlreadyExistsException e) { TempData["error"] = e.Message; } catch (Exception e) { TempData["error"] = e.Message; } return(RedirectToAction(nameof(Index))); }
public IActionResult Post([FromBody] SeatDto dto) { try { addSeat.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(StatusCode(409, new { Errors = new List <string> { e.Message } })); } catch (Exception e) { return(StatusCode(500, new { Errors = new List <string> { e.Message } })); } }
private static bool SeatIsEqual(SeatDto seat1, Seat seat2) { return(seat1.Number == seat2.Number && seat1.LayoutColumn == seat2.LayoutColumn && seat1.LayoutRow == seat2.LayoutRow && seat1.RowId == seat2.RowId); }
public SeatDto GetSeatDetails(int?id) { SeatModel seatModel = _iSeatRepository.GetById(id); SeatDto seatDto = ObjectConverter <SeatModel, SeatDto> .Convert(seatModel); return(seatDto); }
public async Task <SeatDto[, ]> GetLayout(ScheduleDto schedule) { ValidateNull(Logger.Here(), schedule); var seats = (await _unitOfWork.RepositoryInfrastructure.GetActiveSeatsWithRowAndCategoryAsync(schedule.CinemaHallId)) .Select(Map) .ToList(); var cinemaHall = await _unitOfWork.RepositoryInfrastructure.GetCinemaHallByIdAsync(schedule.CinemaHallId); ValidateNull(Logger.Here(), cinemaHall); var freeSeats = (await _unitOfWork.RepositoryTicket.GetFreeSeatsAsync(Map(schedule))).ToList(); var maxRow = cinemaHall.SizeRow; var maxColumn = cinemaHall.SizeColumn; var layout = new SeatDto[maxRow, maxColumn]; for (var row = 0; row < maxRow; ++row) { for (var column = 0; column < maxColumn; ++column) { var seat = seats.SingleOrDefault(s => s.LayoutColumn == column && s.LayoutRow == row); if (seat != null && seat.State != SeatState.Locked) { seat.State = freeSeats.Any(s => s.Id == seat.Id) ? SeatState.Free : SeatState.Occupied; } layout[row, column] = seat; } } return(layout); }
public async Task <SeatDto[, ]> GetLayout(long cinemaHallId) { var seats = (await _unitOfWork.RepositoryInfrastructure.GetActiveSeatsWithRowAndCategoryAsync(cinemaHallId)) .Select(Map) .ToList(); var cinemaHall = await _unitOfWork.RepositoryInfrastructure.GetCinemaHallByIdAsync(cinemaHallId); ValidateNull(Logger.Here(), cinemaHall); var maxRow = cinemaHall.SizeRow; var maxColumn = cinemaHall.SizeColumn; var layout = new SeatDto[maxRow, maxColumn]; for (var row = 0; row < maxRow; ++row) { for (var column = 0; column < maxColumn; ++column) { var seat = seats.SingleOrDefault(s => s.LayoutColumn == column && s.LayoutRow == row); layout[row, column] = seat; } } return(layout); }
public async Task <SeatDto> UpdateSeatAsync(SeatDto seatDto) { ValidateNull(Logger.Here(), seatDto); var seat = Map(seatDto); return((await _unitOfWork.RepositoryInfrastructure.UpdateSeatAsync(seat)) > 0 ? seatDto : null); }
private void ImportSeat(SeatDto seatDto) { string cinemaTown = seatDto.CinemaTown; townValidator.CheckTownExisting(cinemaTown); int townId = townService.GetTownId(cinemaTown); string cinemaName = seatDto.CinemaName; cinemaValidator.CheckCinemaExisting(cinemaName, townId); int cinemaId = cinemaService.GetCinemaId(cinemaName, townId); byte auditoriumNumber = seatDto.AuditoriumNumber; auditoriumValidator.CheckAuditoriumExists(auditoriumNumber, cinemaId, cinemaName); int auditoriumId = auditoriumService.GetAuditoriumId(auditoriumNumber, cinemaId); int row = seatDto.Row; int number = seatDto.Number; seatValidator.ValidateSeatDoesntExist(number, auditoriumId, auditoriumNumber); seatService.AddSeat(number, row, auditoriumId); Console.WriteLine(string.Format(Constants.ImportSuccessMessages.SeatAddedSuccess, number, auditoriumNumber, cinemaName, cinemaTown)); }
public void Execute(SeatDto request) { var seat = Context.Seats.Find(request.Id); if (seat == null || seat.IsDeleted == true) { throw new EntityNotFoundException("Seat"); } if (Context.Halls.Where(h => h.Id == request.HallId).Any(h => h.MaximumOccupancy <= Context.Seats.Where(s => s.HallId == request.HallId).Count())) { throw new Exception("Maximum hall occupancy reached."); } if (seat.Name.ToLower() != request.Name.ToLower() || seat.Number != request.Number && Context.Seats.Any(s => s.Name.ToLower().Contains(request.Name.ToLower()) && s.Number == request.Number && s.HallId == request.HallId)) { throw new EntityAlreadyExistsException("Seat"); } seat.HallId = request.HallId; seat.Name = request.Name; seat.Number = request.Number; seat.IsBroken = request.IsBroken; Context.SaveChanges(); }
public SeatDto Execute(int search) { var query = _context.Seats.Include(x => x.SeatReserveds).Include(x => x.Auditorium).AsQueryable(); var seat = query.FirstOrDefault(s => s.Id == search); if (seat == null) { throw new NotFoundException(search, typeof(Seat)); } var response = new SeatDto { Id = seat.Id, Number = seat.Number, AuditoriumName = seat.Auditorium.Name, SeatReserved = seat.SeatReserveds.Select(r => new SeatReservations { RezervationId = r.ReservationId, ScreeningTime = r.Screening.ScreeningTime }) }; return(response); }
public static Seat MapToSeat(SeatDto from) { return(new Seat { AreaId = from.AreaId, Number = from.Number, Row = from.Row }); }
internal async void UpdateSeat(SeatDto upSeat) { HttpResponseMessage response = await _client.PutAsJsonAsync($"api/Seats/{upSeat.Id}", upSeat); if (!response.IsSuccessStatusCode) { throw new NetworkException("Service returned response: " + response.StatusCode); } }
private ReservedSeats Map(SeatDto seatDto) { return(new ReservedSeats { Name = seatDto.Name, Email = seatDto.Email, SeatId = seatDto.SeatId, }); }
public void CreateSeat_WhenSeatWithSeatAndRowExists_ShouldReturnValidationException() { var seat = new SeatDto { Number = 10, AreaId = 1, Row = 1 }; Assert.Throws <ValidationException>(() => _venueService.CreateSeat(seat)); }
public async Task UpdateSeatAsync(SeatDto seat) { HttpResponseMessage response = await _client.PutAsJsonAsync($"api/Seats/{seat.Id}", seat); if (!response.IsSuccessStatusCode) { throw new NetworkException("Service returned response: " + response.StatusCode); } }
private static ReservationStatus FindReservationStatus(SeatDto seatDto, ReservedSeatsDto reservedSeatsDto) { if (reservedSeatsDto.ReservedSeats.Any(s => s == seatDto.Name)) { return(ReservationStatus.Reserved); } return(ReservationStatus.Available); }
public SeatDto CreateSeat(SeatDto obj) { List <Seat> objs = _seatRepository.GetAll() .Where(a => a.AreaId == obj.AreaId && a.Row == obj.Row && a.Number == obj.Number).ToList(); return(objs.Count == 0 ? ConvertToDto(_seatRepository.Create(ConvertToEntity(obj))) : ConvertToDto(objs.ElementAt(0))); }
public bool IsSeatAlreadyExists(SeatDto seatDto) { var seatList = _iSeatRepository.GetAll().ToList(); return((from s in seatList where s.SeatNo == seatDto.SeatNo && s.Rent == seatDto.Rent && s.SeatTypeId == seatDto.SeatTypeId select s).Any()); }
private static Seat ConvertToEntity(SeatDto obj) { return(new Seat { Id = obj.Id, AreaId = obj.AreaId, Number = obj.Number, Row = obj.Row, }); }
public int CreateSeat(SeatDto seat) { ModelValidation.IsValidModel(seat); if (IsSeatExist(seat)) { throw new ValidationException("Seat can't be created with this seat and row"); } return(_seatRepository.Add(_mapper.Map <Seat>(seat))); }
public bool GetSeatAvailability(string Row, string Column) { var seat = new SeatDto { Row = Row, Column = Column }; return(_seatAvailabilityApplicationService.GetSeatAvailability(seat)); }
public static Seat ToSeatContract(SeatDto from) { return(new Seat { AreaId = from.AreaId, Id = from.Id, Number = from.Number, Row = from.Row }); }
public PassengerDto(Passenger passenger, Guid planeId) { UserName = passenger.UserName; Id = passenger.Id; ReservationNumber = passenger.ReservationCode; PlaneId = planeId; if (passenger.Seat != null) { Seat = new SeatDto(passenger?.Seat); } }
public void CreateSeat_WhenModelValid_ShouldReturnNewId() { var seat = new SeatDto { Number = 11, AreaId = 1, Row = 12 }; var result = _venueService.CreateSeat(seat); Assert.AreEqual(result, ReturnIdSeat); }
private bool IsSeatUnique(SeatDto entity, bool isCreating) { var data = from seats in _context.SeatRepository.GetList() where seats.AreaId == entity.AreaId && seats.Row == entity.Row && seats.Number == entity.Number select seats; return(isCreating ? !data.Any() : !(from seats in data where seats.Id != entity.Id select seats).Any()); }
public static SeatDto GetSeatDto(Seat seat) { var result = new SeatDto() { Id = seat.SeatId, DeveloperId = seat.EmployeeId, RoomId = seat.RoomId, Vertex = new Vertex(seat.X, seat.Y) }; return(result); }
public async Task SeatReservationRequestAsync(long userId, int eventId, SeatDto seatDto, CancellationToken cancellationToken) { var reservedSeat = Map(seatDto); reservedSeat.EventId = eventId; var reservation = _context.Reservations.FirstOrDefaultAsync(x => x.UserId == userId && x.EventId == eventId, cancellationToken); if (reservation != null) { _context.ReservedSeats.Add(reservedSeat); } await _context.SaveChangesAsync(cancellationToken); }
internal async Task <SeatDto> CreateSeat(SeatDto seat) { HttpResponseMessage response = await _client.PostAsJsonAsync("api/Seats/", seat); seat.Id = (await response.Content.ReadAsAsync <SeatDto>()).Id; if (!response.IsSuccessStatusCode) { throw new NetworkException("Service returned response: " + response.StatusCode); } return(seat); }
public SeatDto AddSeat(SeatDto seatDto) { if (_seatRepository.GetAll().Any(x => x.AreaId == seatDto.AreaId && x.Number == seatDto.Number && x.Row == seatDto.Row)) { throw new EntityException("This seat is exist now"); } var id = _seatRepository.Add(_mapper.Map <Seat>(seatDto)); seatDto.Id = id; return(seatDto); }
public ActionResult <SeatDto> PostSeat(SeatDto seatDto) { var seat = _service.CreateSeat((Seat)seatDto); if (seat is null) { return(StatusCode(StatusCodes.Status500InternalServerError)); } else { return(CreatedAtAction(nameof(GetSeat), new { id = seat.Id }, (SeatDto)seat)); } }