public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_AuditoriumWithSameNameExists() { //Arrange CreateAuditoriumResultModel expectedResultModel = new CreateAuditoriumResultModel() { ErrorMessage = "Cannot create new auditorium, auditorium with same name already exist.", IsSuccessful = false }; IEnumerable <Auditorium> auditoriums = _listOFAuditoriums; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; var numberOfSeatsPerRow = 2; var numberOfRows = 2; Data.Cinema cinema = _cinema; Task <Data.Cinema> responseTaskCinemasRepository = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTaskCinemasRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); Task <IEnumerable <Auditorium> > responseTaskAuditoriumsRepository = Task.FromResult(auditoriums); _mockAuditoriumsRepository.Setup(x => x.GetByAuditName(auditoriumDomainModel.Name, cinema.Id)).Returns(responseTaskAuditoriumsRepository); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedResultModel.ErrorMessage, resultAction.ErrorMessage); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); }
public async Task <IEnumerable <CinemaDomainModel> > GetAllAsync() { var data = await _cinemasRepository.GetAll(); List <CinemaDomainModel> result = new List <CinemaDomainModel>(); CinemaDomainModel model; foreach (var cinema in data) { model = new CinemaDomainModel { Id = cinema.Id, Name = cinema.Name, CityId = cinema.CityId, AuditoriumsList = new List <AuditoriumDomainModel>() }; foreach (var auditorium in cinema.Auditoriums) { AuditoriumDomainModel auditoriumModel = new AuditoriumDomainModel { Id = auditorium.Id, CinemaId = cinema.Id, Name = auditorium.AuditName }; model.AuditoriumsList.Add(auditoriumModel); } result.Add(model); } return(result); }
public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_InvalidCinemaId() { //Arrange CreateAuditoriumResultModel expectedResultModel = new CreateAuditoriumResultModel() { ErrorMessage = "Cannot create new auditorium, auditorium with given cinemaId does not exist.", IsSuccessful = false }; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; var numberOfSeatsPerRow = 2; var numberOfRows = 2; Data.Cinema cinema = null; Task <Data.Cinema> responseTask = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedResultModel.ErrorMessage, resultAction.ErrorMessage); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); }
public IEnumerable <AuditoriumDomainModel> GetAllOfSpecificCinema(int id) { var data = _auditoriumsRepository.GetAllOfSpecificCinema(id); if (data == null) { return(null); } List <AuditoriumDomainModel> result = new List <AuditoriumDomainModel>(); AuditoriumDomainModel model; foreach (var item in data) { model = new AuditoriumDomainModel { Id = item.Id, CinemaId = item.CinemaId, Name = item.Name }; result.Add(model); } return(result); }
public void TestInitialize() { _auditorium = new Auditorium { Id = 1, CinemaId = 1, AuditName = "Novi auditorium", }; _auditoriumDomainModel = new AuditoriumDomainModel { Id = _auditorium.Id, CinemaId = _auditorium.CinemaId, Name = _auditorium.AuditName }; _cinema = new Data.Cinema { Id = 1, CityId = 1, Name = "test bioskop 1" }; _cinemaDomainModel = new CinemaDomainModel { Id = _cinema.Id, CityId = _cinema.CityId, Name = _cinema.Name }; _mockAuditoriumRepository = new Mock <IAuditoriumsRepository>(); _mockCinemaRepository = new Mock <ICinemasRepository>(); _auditoriumService = new AuditoriumService(_mockAuditoriumRepository.Object, _mockCinemaRepository.Object); }
public async Task <IEnumerable <AuditoriumDomainModel> > GetAllAsync() { var data = await _auditoriumsRepository.GetAll(); if (data == null) { return(null); } List <AuditoriumDomainModel> result = new List <AuditoriumDomainModel>(); AuditoriumDomainModel model; foreach (var item in data) { model = new AuditoriumDomainModel { Id = item.Id, CinemaId = item.CinemaId, Name = item.Name }; result.Add(model); } return(result); }
public void AuditoriumService_UpdateAuditorium_Returns_AuditoriumResultModel_Successful() { //Arrange AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; Auditorium auditorium = _auditorium; IEnumerable <Projection> projections = null; IEnumerable <Seat> seats = null; _mockProjectionRepository = new Mock <IProjectionsRepository>(); _mockProjectionRepository.Setup(x => x.GetAllOfSpecificAuditorium(It.IsAny <int>())).Returns(projections); _mockSeatsRepository = new Mock <ISeatsRepository>(); _mockSeatsRepository.Setup(x => x.GetAllOfSpecificAuditorium(It.IsAny <int>())).Returns(seats); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockAuditoriumsRepository.Setup(x => x.Update(It.IsAny <Auditorium>())).Returns(auditorium); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.UpdateAuditorium(auditoriumDomainModel).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.IsTrue(resultAction.IsSuccessful); Assert.IsNull(resultAction.ErrorMessage); Assert.IsInstanceOfType(resultAction, typeof(AuditoriumResultModel)); Assert.AreEqual(auditoriumDomainModel.Name, resultAction.Auditorium.Name); }
public async Task <IEnumerable <AuditoriumDomainModel> > GetAllAuditoriums() { var data = await _auditoriumRepository.GetAll(); if (data == null) { return(null); } List <AuditoriumDomainModel> list = new List <AuditoriumDomainModel>(); AuditoriumDomainModel model; foreach (var item in data) { model = new AuditoriumDomainModel { AuditoriumId = item.AuditoriumId, NameOfAuditorium = item.AuditoriumName, NumberOfSeats = item.NumberOfSeats, MuseumId = item.MuseumId }; list.Add(model); } return(list); }
public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_Successful() { IEnumerable <Auditorium> auditoriums = _listOFAuditoriums; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; Auditorium auditorium = _auditorium; Auditorium newAuditorium = _newAuditorium; var numberOfSeatsPerRow = 1; var numberOfRows = 1; Data.Cinema cinema = _cinema; Task <Data.Cinema> responseTaskCinemasRepository = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTaskCinemasRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); Task <IEnumerable <Auditorium> > responseTaskAuditoriumsRepository = Task.FromResult(auditoriums); _mockAuditoriumsRepository.Setup(x => x.GetByAuditName(auditoriumDomainModel.Name, cinema.Id)).Returns(responseTaskAuditoriumsRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockAuditoriumsRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(newAuditorium); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.IsNull(resultAction.ErrorMessage); Assert.IsTrue(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); Assert.AreEqual(1, resultAction.Auditorium.Id); }
public async Task <AuditoriumResultModel> CreateAuditorium(AuditoriumDomainModel createAuditorium) { AuditoriumEntity newAuditorium = new AuditoriumEntity { AuditoriumId = createAuditorium.AuditoriumId, AuditoriumName = createAuditorium.NameOfAuditorium, MuseumId = createAuditorium.MuseumId, NumberOfSeats = createAuditorium.NumberOfSeats }; bool museum = false; var listOfMuseums = await _museumsRepository.GetAll(); foreach (var item in listOfMuseums) { if (item.MuseumId == createAuditorium.MuseumId) { museum = true; } ; } if (museum == false) { return(new AuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.MUSEUM_DOES_NOT_EXIST, Auditorium = null }); } var auditorium = _auditoriumRepository.Insert(newAuditorium); if (auditorium == null) { return(new AuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_WITH_THIS_ID_ALREADY_EXISTS, Auditorium = null }); } AuditoriumResultModel result = new AuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = new AuditoriumDomainModel { AuditoriumId = auditorium.AuditoriumId, NameOfAuditorium = auditorium.AuditoriumName, MuseumId = auditorium.MuseumId, NumberOfSeats = auditorium.NumberOfSeats } }; return(result); }
public async Task <ActionResult> Edit(int id, [FromBody] CreateAuditoriumModel auditoriumModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AuditoriumDomainModel auditoriumToUpdate; auditoriumToUpdate = await _auditoriumService.GetByIdAsync(id); if (auditoriumToUpdate == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.AUDITORIUM_DOES_NOT_EXIST, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } AuditoriumDomainModel domainModel = new AuditoriumDomainModel() { Id = id, CinemaId = auditoriumModel.cinemaId, Name = auditoriumModel.auditName }; AuditoriumDomainModel auditoriumDomainModel; try { auditoriumDomainModel = await _auditoriumService.UpdateAuditorium(domainModel, auditoriumModel.seatRows, auditoriumModel.numberOfSeats); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } return(Accepted("auditoriums//" + auditoriumDomainModel.Id, auditoriumDomainModel)); }
public async Task <IEnumerable <AuditoriumDomainModel> > DeleteAuditoriumsByCinemaId(int cinemaId) { var auditoriumsToBeDeleted = await _auditoriumsRepository.GetByCinemaId(cinemaId); if (auditoriumsToBeDeleted == null) { return(null); } auditoriumsToBeDeleted.ToList(); List <AuditoriumDomainModel> deletedAuditoriums = new List <AuditoriumDomainModel>(); foreach (Auditorium auditorium in auditoriumsToBeDeleted) { var deletedProjection = await _projectionService.DeleteByAuditoriumId(auditorium.Id); if (deletedProjection == null) { return(null); } var deletedSeats = await _seatService.DeleteByAuditoriumId(auditorium.Id); if (deletedSeats == null) { return(null); } var deletedAuditorium = _auditoriumsRepository.Delete(auditorium.Id); if (deletedAuditorium == null) { return(null); } AuditoriumDomainModel domainModel = new AuditoriumDomainModel { CinemaId = deletedAuditorium.CinemaId, Id = deletedAuditorium.Id, Name = deletedAuditorium.Name, SeatsList = deletedSeats.ToList() }; deletedAuditoriums.Add(domainModel); } return(deletedAuditoriums); }
public void TestInitialize() { _auditorium = new Auditorium() { Id = 1, CinemaId = 1, Name = "AuditoriumName", Seats = new List <Seat>() }; _auditoriumDomainModel = new AuditoriumDomainModel() { Id = 1, Name = "AuditoriumName", CinemaId = 1 }; _cinema = new Data.Cinema() { Name = "CinemaName", Id = 1 }; _newAuditorium = new Auditorium(); _newAuditorium = _auditorium; _newAuditorium.Seats.Add(new Seat() { Number = 1, Row = 1, AuditoriumId = 1 }); _projection = new Projection() { AuditoriumId = 1, DateTime = DateTime.Now.AddDays(1), Id = Guid.NewGuid(), MovieId = Guid.NewGuid() }; _listOfProjections = new List <Projection>(); _listOfProjections.Add(_projection); _listOFAuditoriums = new List <Auditorium>(); _listOFAuditoriums.Add(_auditorium); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockSeatsRepository = new Mock <ISeatsRepository>(); _mockProjectionRepository = new Mock <IProjectionsRepository>(); _mockTicketService = new Mock <ITicketService>(); }
public async Task <AuditoriumDomainModel> GetAuditoriumByIdAsync(int id) { var data = await _auditoriumsRepository.GetByIdAsync(id); if (data == null) { return(null); } AuditoriumDomainModel domainModel = new AuditoriumDomainModel { Id = data.Id, Name = data.Name, CinemaId = data.CinemaId }; return(domainModel); }
public async Task <ActionResult <AuditoriumDomainModel> > PostAsync(CreateAuditoriumModel createAuditoriumModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AuditoriumDomainModel auditoriumDomainModel = new AuditoriumDomainModel { CinemaId = createAuditoriumModel.cinemaId, Name = createAuditoriumModel.auditName }; CreateAuditoriumResultModel createAuditoriumResultModel; try { createAuditoriumResultModel = await _auditoriumService.CreateAuditorium(auditoriumDomainModel, createAuditoriumModel.numberOfSeats, createAuditoriumModel.seatRows); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (!createAuditoriumResultModel.IsSuccessful) { ErrorResponseModel errorResponse = new ErrorResponseModel() { ErrorMessage = createAuditoriumResultModel.ErrorMessage, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } return(Created("auditoriums//" + createAuditoriumResultModel.Auditorium.Id, createAuditoriumResultModel)); }
public async Task <AuditoriumResultModel> UpdateAuditorium(AuditoriumDomainModel updateAuditorium) { var data = await _auditoriumRepository.GetByIdAsync(updateAuditorium.AuditoriumId); AuditoriumEntity auditorium = new AuditoriumEntity { AuditoriumId = updateAuditorium.AuditoriumId, MuseumId = updateAuditorium.MuseumId, AuditoriumName = updateAuditorium.NameOfAuditorium, NumberOfSeats = updateAuditorium.NumberOfSeats }; var auditoriumUpdate = _auditoriumRepository.Update(auditorium); if (auditoriumUpdate == null) { return(new AuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_UPDATE_ERROR, Auditorium = null }); } _auditoriumRepository.Save(); AuditoriumResultModel result = new AuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = new AuditoriumDomainModel { MuseumId = auditoriumUpdate.MuseumId, AuditoriumId = auditoriumUpdate.AuditoriumId, NameOfAuditorium = auditoriumUpdate.AuditoriumName, NumberOfSeats = auditoriumUpdate.NumberOfSeats } }; return(result); }
public async Task <AuditoriumDomainModel> GetAuditoriumByIdAsync(int id) { var data = await _auditoriumRepository.GetByIdAsync(id); if (data == null) { return(null); } AuditoriumDomainModel result; result = new AuditoriumDomainModel { AuditoriumId = data.AuditoriumId, NameOfAuditorium = data.AuditoriumName, NumberOfSeats = data.NumberOfSeats, MuseumId = data.MuseumId }; return(result); }
public async Task <IEnumerable <AuditoriumDomainModel> > GetAllAuditoriums() { var data = await _auditoriumsRepository.GetAllAsync(); List <AuditoriumDomainModel> result = new List <AuditoriumDomainModel>(); AuditoriumDomainModel model; foreach (var item in data) { model = new AuditoriumDomainModel { Id = item.Id, TheatreId = item.TheatreId, Name = item.Name, TheatreName = item.Theatre.Name }; result.Add(model); } return(result); }
public void Get_Async_Return_All_Cinemas_By_CinemaId() { //Arrange List <AuditoriumDomainModel> auditoriumsDomainModelsList = new List <AuditoriumDomainModel>(); AuditoriumDomainModel auditoriumDomainModel = new AuditoriumDomainModel { Id = 1, Name = "Auditorium1", CinemaId = 5, SeatsList = new List <SeatDomainModel>() }; auditoriumsDomainModelsList.Add(auditoriumDomainModel); IEnumerable <AuditoriumDomainModel> auditoriumDomainModels = auditoriumsDomainModelsList; IEnumerable <AuditoriumDomainModel> responseTask = auditoriumDomainModels; int expectedResultCount = 1; int expectedStatusCode = 200; _auditoriumService = new Mock <IAuditoriumService>(); _auditoriumService.Setup(x => x.GetAuditoriumsByCinemaId(It.IsAny <int>())).Returns(responseTask); AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object); //Act var result = auditoriumsController.GetAuditoriumsByCinemaId(auditoriumDomainModel.CinemaId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var auditoriumDomainModelResultList = (List <AuditoriumDomainModel>)resultList; //Assert Assert.IsNotNull(auditoriumDomainModelResultList); Assert.AreEqual(expectedResultCount, auditoriumDomainModelResultList.Count); Assert.AreEqual(auditoriumDomainModel.Id, auditoriumDomainModelResultList[0].Id); Assert.AreEqual(auditoriumDomainModel.CinemaId, auditoriumDomainModelResultList[0].CinemaId); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void AuditoriumService_UpdateAuditorium_Returns_AuditoriumResultModel_AuditoriumUpdateError_ProjectionInFuture() { //Arrange AuditoriumResultModel expectedResultModel = new AuditoriumResultModel() { ErrorMessage = "Unable to update auditorium, please make sure there no upcoming projections and then try again. " }; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; IEnumerable <Projection> projections = _listOfProjections; _mockProjectionRepository = new Mock <IProjectionsRepository>(); _mockProjectionRepository.Setup(x => x.GetAllOfSpecificAuditorium(It.IsAny <int>())).Returns(_listOfProjections); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.UpdateAuditorium(auditoriumDomainModel).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.IsFalse(resultAction.IsSuccessful); Assert.AreEqual(expectedResultModel.ErrorMessage, resultAction.ErrorMessage); Assert.IsInstanceOfType(resultAction, typeof(AuditoriumResultModel)); }
public async Task <AuditoriumDomainModel> GetByIdAsync(int id) { var data = await _auditoriumsRepository.GetByIdAsync(id); if (data == null) { return(null); } List <SeatDomainModel> domainModelList = new List <SeatDomainModel>(); if (data.Seats != null) { foreach (Seat seat in data.Seats) { SeatDomainModel domainModel = new SeatDomainModel() { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Number = seat.Number, Row = seat.Row }; domainModelList.Add(domainModel); } } AuditoriumDomainModel result = new AuditoriumDomainModel() { Id = data.Id, CinemaId = data.CinemaId, Name = data.Name, SeatsList = domainModelList }; return(result); }
public async Task <AuditoriumDomainModel> DeleteAuditorium(int auditoriumId) { var deletedProjections = await _projectionService.DeleteByAuditoriumId(auditoriumId); if (deletedProjections == null) { return(null); } var deletedSeats = await _seatService.DeleteByAuditoriumId(auditoriumId); if (deletedSeats == null) { return(null); } var deletedAuditorium = _auditoriumsRepository.Delete(auditoriumId); if (deletedAuditorium == null) { return(null); } _auditoriumsRepository.Save(); AuditoriumDomainModel result = new AuditoriumDomainModel { CinemaId = deletedAuditorium.CinemaId, Id = deletedAuditorium.Id, Name = deletedAuditorium.Name, SeatsList = deletedSeats.ToList() }; return(result); }
public async Task <IEnumerable <TheatreDomainModel> > GetAllAsync() { var data = await _theatreRepository.GetAllAsync(); List <TheatreDomainModel> result = new List <TheatreDomainModel>(); TheatreDomainModel model; foreach (var theatre in data) { model = new TheatreDomainModel { Id = theatre.Id, Name = theatre.Name, AddressId = theatre.AddressId, CityName = theatre.Address.CityName, StreetName = theatre.Address.StreetName, AuditoriumsList = new List <AuditoriumDomainModel>() }; foreach (var auditorium in theatre.Auditoriums) { AuditoriumDomainModel auditoriumModel = new AuditoriumDomainModel { Id = auditorium.Id, TheatreId = theatre.Id, Name = auditorium.Name }; model.AuditoriumsList.Add(auditoriumModel); } result.Add(model); } return(result); }
public async Task <CreateAuditoriumResultModel> CreateAuditorium(AuditoriumDomainModel domainModel, int numberOfRows, int numberOfSeats) { var cinema = await _cinemasRepository.GetByIdAsync(domainModel.CinemaId); if (cinema == null) { return(new CreateAuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_UNVALID_CINEMAID }); } var auditorium = await _auditoriumsRepository.GetByAuditName(domainModel.Name, domainModel.CinemaId); var sameAuditoriumName = auditorium.ToList(); if (sameAuditoriumName != null && sameAuditoriumName.Count > 0) { return(new CreateAuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_SAME_NAME }); } Auditorium newAuditorium = new Auditorium { Name = domainModel.Name, CinemaId = domainModel.CinemaId, }; newAuditorium.Seats = new List <Seat>(); for (int i = 1; i <= numberOfRows; i++) { for (int j = 1; j <= numberOfSeats; j++) { Seat newSeat = new Seat() { Row = i, Number = j }; newAuditorium.Seats.Add(newSeat); } } Auditorium insertedAuditorium = _auditoriumsRepository.Insert(newAuditorium); if (insertedAuditorium == null) { return(new CreateAuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR }); } CreateAuditoriumResultModel resultModel = new CreateAuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = new AuditoriumDomainModel { Id = insertedAuditorium.Id, Name = insertedAuditorium.Name, CinemaId = insertedAuditorium.CinemaId, SeatsList = new List <SeatDomainModel>() } }; foreach (var item in insertedAuditorium.Seats) { resultModel.Auditorium.SeatsList.Add(new SeatDomainModel { AuditoriumId = insertedAuditorium.Id, Id = item.Id, Number = item.Number, Row = item.Row }); } return(resultModel); }
public async Task <AuditoriumDomainModel> UpdateAuditorium(AuditoriumDomainModel updatedAuditorium, int numberOfRows, int numberOfColumns) { var originalAuditoriumSeats = await _seatService.GetSeatsByAuditoriumId(updatedAuditorium.Id); if (originalAuditoriumSeats == null) { return(null); } // Proveravanje trenutnog stanja auditorijuma int maxRow = 1; int maxColumn = 1; void setMax(IEnumerable <SeatDomainModel> audit) { foreach (SeatDomainModel seat in audit) { if (seat.Row > maxRow) { maxRow = seat.Row; } if (seat.Number > maxColumn) { maxColumn = seat.Number; } } } void setMaxRow(IEnumerable <SeatDomainModel> audit) { foreach (SeatDomainModel seat in audit) { maxRow = 1; if (seat.Row > maxRow) { maxRow = seat.Row; } } } setMax(originalAuditoriumSeats); // Uspostavljanje parametara za izmenu stanja sedista updatedAuditorium.SeatsList = originalAuditoriumSeats.ToList(); int rowDelta = numberOfRows - maxRow; // parametar koji definise kako se menja broj kolona moze biti pozitivan i negativan int columnDelta = numberOfColumns - maxColumn; // parametar koji definise kako se menja broj redova moze biti pozitivan i negativan if (rowDelta != 0 || columnDelta != 0) { int i = 0, j = 0; // brojaci // ako treba da se dodaju redovi if (rowDelta > 0) { for (i = maxRow + 1; i <= maxRow + rowDelta; i++) { for (j = 1; j <= maxColumn; j++) { SeatDomainModel newSeat = new SeatDomainModel() { AuditoriumId = updatedAuditorium.Id, Row = i, Number = j }; // sedista se dodaju u objekat koji ce se updejtovati updatedAuditorium.SeatsList.Add(newSeat); } } setMaxRow(updatedAuditorium.SeatsList); } // ako treba da se izbrisu redovi else if (rowDelta < 0) { for (i = maxRow; i > maxRow + rowDelta; i--) { for (j = 1; j <= maxColumn; j++) { // sedista se brisu iz baze var seatToDelete = await _seatService.GetSeatByAuditoriumIdRowSeatnum(updatedAuditorium.Id, i, j); if (seatToDelete == null) { continue; } // ovo je neophodno jer navodno ne moze da se radi .remove preko kopije objekta nego mora da bude 'isti tip objekta' var seatListObjectToRemove = updatedAuditorium.SeatsList.Where(x => x.Id == seatToDelete.Id).FirstOrDefault(); updatedAuditorium.SeatsList.Remove(seatListObjectToRemove); var result = await _seatService.DeleteSeat(seatToDelete.Id); if (result == null) { return(null); } } } setMaxRow(updatedAuditorium.SeatsList); } if (columnDelta > 0) { for (i = 1; i <= maxRow; i++) { for (j = maxColumn + 1; j <= maxColumn + columnDelta; j++) { SeatDomainModel newSeat = new SeatDomainModel() { AuditoriumId = updatedAuditorium.Id, Row = i, Number = j }; // sedista se dodaju u objekat koji ce se updejtovati updatedAuditorium.SeatsList.Add(newSeat); } } } else if (columnDelta < 0) { for (i = 1; i <= maxRow; i++) { for (j = maxColumn; j > maxColumn + columnDelta; j--) { // ovde skidanje sa liste ide prvo jer sedista koja su samo dodata na listu a nisu u bazu takodje treba da se obrisu var seatListObjectToRemove = updatedAuditorium.SeatsList.Where(x => x.AuditoriumId == updatedAuditorium.Id && x.Row == i && x.Number == j).FirstOrDefault(); updatedAuditorium.SeatsList.Remove(seatListObjectToRemove); // sedista se brisu iz baze var seatToDelete = await _seatService.GetSeatByAuditoriumIdRowSeatnum(updatedAuditorium.Id, i, j); if (seatToDelete == null) { continue; } var result = _seatService.DeleteSeat(seatToDelete.Id); if (result == null) { return(null); } } } foreach (SeatDomainModel seat in updatedAuditorium.SeatsList) { if (seat.Row > maxRow) { maxRow = seat.Row; } } ; } } // SeatDomainModel se prevode u SeatList da bi se Auditorium objekat uneo u bazu List <Seat> auditoriumSeatList = new List <Seat>(); foreach (SeatDomainModel domainModel in updatedAuditorium.SeatsList) { Seat seat = new Seat() { Id = domainModel.Id, AuditoriumId = domainModel.AuditoriumId, Row = domainModel.Row, Number = domainModel.Number }; auditoriumSeatList.Add(seat); } // Kreira se updejtovani objekat za unos u bazu Auditorium auditorium = new Auditorium() { CinemaId = updatedAuditorium.CinemaId, Id = updatedAuditorium.Id, Name = updatedAuditorium.Name, Seats = auditoriumSeatList }; // Updejtovani auditorijum se vraca u bazu var data = _auditoriumsRepository.Update(auditorium); if (data == null) { return(null); } _auditoriumsRepository.Save(); // Prevodjenje vracenog Auditorijuma u AuditoriumDomainModel i return List <SeatDomainModel> resultSeatList = new List <SeatDomainModel>(); foreach (Seat seat in data.Seats) { SeatDomainModel seatDomainModel = new SeatDomainModel() { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Row = seat.Row, Number = seat.Number }; resultSeatList.Add(seatDomainModel); } AuditoriumDomainModel returnResult = new AuditoriumDomainModel() { Id = data.Id, CinemaId = data.CinemaId, Name = data.Name, SeatsList = resultSeatList }; return(returnResult); }
public async Task <TheatreDomainModel> Create(TheatreDomainModel theatreDomainModel, int numOfSeats, int numOfRows, string auditoriumName) { var theatres = await _theatreRepository.GetAllAsync(); foreach (var theatre in theatres) { if (theatre.Address.CityName == theatreDomainModel.CityName) { if (theatre.Name == theatreDomainModel.Name || theatre.Address.StreetName == theatreDomainModel.StreetName) { return(null); } } } Theatre newTheatre = new Theatre { Name = theatreDomainModel.Name, Address = new Address { CityName = theatreDomainModel.CityName, StreetName = theatreDomainModel.StreetName } }; newTheatre.Auditoriums = new List <Auditorium>(); Auditorium auditorium = new Auditorium { Name = auditoriumName }; auditorium.Seats = new List <Seat>(); for (int j = 1; j <= numOfRows; j++) { for (int k = 1; k <= numOfSeats; k++) { Seat seat = new Seat { Row = j, Number = k }; auditorium.Seats.Add(seat); } } newTheatre.Auditoriums.Add(auditorium); Theatre insertedTheatre = _theatreRepository.Insert(newTheatre); if (insertedTheatre == null) { return(null); } _theatreRepository.Save(); if (insertedTheatre == null) { return(null); } TheatreDomainModel theatreModel = new TheatreDomainModel { Id = insertedTheatre.Id, Name = insertedTheatre.Name, AddressId = insertedTheatre.AddressId, AuditoriumsList = new List <AuditoriumDomainModel>() }; foreach (var auditoriumInserted in insertedTheatre.Auditoriums) { AuditoriumDomainModel modelAuditoroum = new AuditoriumDomainModel { Id = auditoriumInserted.Id, TheatreId = insertedTheatre.Id, Name = auditoriumInserted.Name, SeatsList = new List <SeatDomainModel>() }; foreach (var seat in auditoriumInserted.Seats) { modelAuditoroum.SeatsList.Add(new SeatDomainModel { Id = seat.Id, AuditoriumId = auditoriumInserted.Id, Number = seat.Number, Row = seat.Row }); } theatreModel.AuditoriumsList.Add(modelAuditoroum); } return(theatreModel); }
// CreateAuditorium(AuditoriumDomainModel domainModel, int numberOfRows, int numberOfSeats) public async Task <CreateCinemaResultModel> AddCinemaWithAuditorium(CreateCinemaWithAuditoriumModel newCinemaWithAuditorium) { var cinema = await _cinemasRepository.GetByCinemaName(newCinemaWithAuditorium.CinemaName); var sameCinemaName = cinema.ToList(); if (sameCinemaName != null && sameCinemaName.Count > 0) { return(new CreateCinemaResultModel { IsSuccessful = false, ErrorMessage = Messages.CINEMA_SAME_NAME }); } Data.Cinema cinemaToCreate = new Data.Cinema() { Name = newCinemaWithAuditorium.CinemaName }; var cinemaData = _cinemasRepository.Insert(cinemaToCreate); if (cinemaData == null) { return(new CreateCinemaResultModel { IsSuccessful = false, ErrorMessage = Messages.CINEMA_CREATION_ERROR }); } _cinemasRepository.Save(); AuditoriumDomainModel auditoriumToCreate = new AuditoriumDomainModel() { CinemaId = cinemaData.Id, Name = newCinemaWithAuditorium.AuditoriumName }; var auditoriumData = await _auditoriumService.CreateAuditorium(auditoriumToCreate, newCinemaWithAuditorium.NumberOfRows, newCinemaWithAuditorium.NumberOfColumns); if (auditoriumData == null) { return(new CreateCinemaResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR }); } List <AuditoriumDomainModel> auditoriumDomainModels = new List <AuditoriumDomainModel>(); auditoriumDomainModels.Add(auditoriumData.Auditorium); CinemaDomainModel createdCinema = new CinemaDomainModel() { Id = cinemaData.Id, Name = cinemaData.Name, AuditoriumsList = auditoriumDomainModels }; CreateCinemaResultModel cinemaResultModel = new CreateCinemaResultModel() { IsSuccessful = true, ErrorMessage = null, Cinema = createdCinema }; return(cinemaResultModel); }
public async Task <CreateAuditoriumResultModel> AddAuditorium(AuditoriumDomainModel domainModel, int numberOfRows, int numberOfSeats) { var theatre = await _theatreRepository.GetByIdAsync(domainModel.TheatreId); if (theatre == null) { return(new CreateAuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_INVALID_THEATREID }); } Auditorium newAuditorium = new Auditorium { Name = domainModel.Name, TheatreId = domainModel.TheatreId }; newAuditorium.Seats = new List <Seat>(); for (int i = 1; i <= numberOfRows; i++) { for (int j = 1; j <= numberOfSeats; j++) { Seat newSeat = new Seat() { Row = i, Number = j }; newAuditorium.Seats.Add(newSeat); } } Auditorium insertedAuditorium = _auditoriumsRepository.Insert(newAuditorium); if (insertedAuditorium == null) { return(new CreateAuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR }); } _auditoriumsRepository.Save(); CreateAuditoriumResultModel resultModel = new CreateAuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = new AuditoriumDomainModel { Id = insertedAuditorium.Id, Name = insertedAuditorium.Name, TheatreId = insertedAuditorium.TheatreId, SeatsList = new List <SeatDomainModel>() } }; foreach (var item in insertedAuditorium.Seats) { resultModel.Auditorium.SeatsList.Add(new SeatDomainModel { AuditoriumId = insertedAuditorium.Id, Id = item.Id, Number = item.Number, Row = item.Row }); } return(resultModel); }
public void TestInitialize() { _auditorium = new Auditorium { Id = 1, CinemaId = 1, Name = "AuditoriumIme", Cinema = new Data.Cinema { Name = "Bioskop" } }; _auditoriumDomainModel = new AuditoriumDomainModel { Id = _auditorium.Id, CinemaId = _auditorium.CinemaId, Name = _auditorium.Name }; _projectionDomainModel = new ProjectionDomainModel { AuditoriumId = _auditoriumDomainModel.Id, Id = Guid.NewGuid(), AuditoriumName = _auditoriumDomainModel.Name, MovieId = Guid.NewGuid(), MovieRating = 1, MovieTitle = "imefilmea", MovieYear = 1992, ProjectionTime = DateTime.Now.AddDays(1) }; _seatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = _auditoriumDomainModel.Id, Row = 1, Number = 1 }; List <Auditorium> auditoriumsModelsList = new List <Auditorium>(); auditoriumsModelsList.Add(_auditorium); IEnumerable <Auditorium> auditoriums = auditoriumsModelsList; Task <IEnumerable <Auditorium> > responseTask = Task.FromResult(auditoriums); List <ProjectionDomainModel> projectionsModelsList = new List <ProjectionDomainModel>(); projectionsModelsList.Add(_projectionDomainModel); IEnumerable <ProjectionDomainModel> projections = projectionsModelsList; Task <IEnumerable <ProjectionDomainModel> > projectionsResponseTask = Task.FromResult(projections); List <SeatDomainModel> seatsModelsList = new List <SeatDomainModel>(); seatsModelsList.Add(_seatDomainModel); IEnumerable <SeatDomainModel> seats = seatsModelsList; Task <IEnumerable <SeatDomainModel> > seatsResponseTask = Task.FromResult(seats); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockProjectionService = new Mock <IProjectionService>(); _mockSeatService = new Mock <ISeatService>(); }
public async Task <AuditoriumResultModel> UpdateAuditorium(AuditoriumDomainModel auditoriumToUpdate) { var projectionsInAuditorium = _projectionsRepository.GetAllOfSpecificAuditorium(auditoriumToUpdate.Id); if (projectionsInAuditorium != null) { foreach (var item in projectionsInAuditorium) { if (item.DateTime > DateTime.Now) { return(new AuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_UPDATE_ERROR_PROJECTION_IN_FUTURE }); } } } var seatsInAuditorium = _seatsRepository.GetAllOfSpecificAuditorium(auditoriumToUpdate.Id); if (seatsInAuditorium != null) { foreach (var item in seatsInAuditorium) { await _ticketService.DeleteTicket(item.Id); _seatsRepository.Delete(item.Id); } } Auditorium auditorium = new Auditorium() { Id = auditoriumToUpdate.Id, Name = auditoriumToUpdate.Name, CinemaId = auditoriumToUpdate.CinemaId, Seats = new List <Seat>() }; for (int i = 1; i <= auditoriumToUpdate.SeatRows; i++) { for (int j = 1; j <= auditoriumToUpdate.NumberOfSeats; j++) { Seat newSeat = new Seat() { Row = i, Number = j }; auditorium.Seats.Add(newSeat); } } var data = _auditoriumsRepository.Update(auditorium); if (data == null) { return(new AuditoriumResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_UPDATE_ERROR }); } _auditoriumsRepository.Save(); AuditoriumResultModel domainModel = new AuditoriumResultModel { ErrorMessage = null, IsSuccessful = true, Auditorium = new AuditoriumDomainModel { CinemaId = data.CinemaId, Id = data.Id, Name = data.Name, NumberOfSeats = data.Seats.Select(x => x.Number).Count(), SeatRows = data.Seats.Select(x => x.Row).Count(), } }; return(domainModel); }