public async Task <IActionResult> Create(CinemaViewModel model) { var user = await GetCurrentUserAsync(); var userId = user?.Id; string mail = user?.Email; model.CreatedByUserId = userId; model.LastModifiedByUserId = userId; var result = await UploadImage(model.Image); var test = result as ObjectResult; model.ImagePath = test.Value.ToString(); var cinemaAdded = _cinemaService.AddCinema(model); if (cinemaAdded) { var listOfAllCinemas = _cinemaService.GetAllCinemas(); return(View("Index", listOfAllCinemas.ToList()).WithSuccess("Info!", "Cinema was created successfully!")); } return(BadRequest()); }
public async Task <ActionResult> Post([FromBody] CinemaModel cinemaModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CinemaDomainModel cinemaWithoutAuditorium = new CinemaDomainModel() { Name = cinemaModel.Name }; CreateCinemaWithAuditoriumModel cinemaWithAuditoriumModel = new CreateCinemaWithAuditoriumModel { AuditoriumName = cinemaModel.auditName, CinemaName = cinemaModel.Name, NumberOfRows = cinemaModel.seatRows, NumberOfColumns = cinemaModel.numberOfSeats }; CreateCinemaResultModel createCinema; try { if (cinemaModel.auditName != null && cinemaModel.numberOfSeats > 0 && cinemaModel.seatRows > 0) { createCinema = await _cinemaService.AddCinemaWithAuditorium(cinemaWithAuditoriumModel); } else { createCinema = await _cinemaService.AddCinema(cinemaWithoutAuditorium); } } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createCinema.IsSuccessful != true) { ErrorResponseModel errorResponse = new ErrorResponseModel() { ErrorMessage = createCinema.ErrorMessage, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } return(Created("cinemas//" + createCinema.Cinema.Id, createCinema.Cinema)); }
public async Task <ActionResult> Post([FromBody] CinemaModels cinemaModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CinemaDomainModel domainModel = new CinemaDomainModel { Name = cinemaModel.Name }; CreateCinemaResultModel createCienema; try { createCienema = await _cinemaService.AddCinema(domainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createCienema == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.CINEMA_CREATION_ERROR, StatusCode = System.Net.HttpStatusCode.InternalServerError }; return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, errorResponse)); } return(Created("cinemas//" + createCienema.Cinema.Id, createCienema.Cinema)); }
public void GetAllCinemas() { CinemaViewModel cinema = new CinemaViewModel() { CinemaName = "My testing cinema", CinemaDescription = "My testing cinema description", CinemaProfilePicture = "Test picture url", AdminUserId = "d3956f65-2089-470c-b0d9-a15832c8bdab", AdressId = 2, SeatsRows = 10, SeatColumns = 20, CreatedByUserId = "d3956f65-2089-470c-b0d9-a15832c8bdab", LastModifiedByUserId = "d3956f65-2089-470c-b0d9-a15832c8bdab", CreatedOnDate = DateTime.Now.ToString("dd/MM/yyyy"), LastModifiedOnDate = DateTime.Now.ToString("dd/MM/yyyy"), IsDeleted = false }; Assert.True(_cinemaService.AddCinema(cinema)); }
public async Task <ActionResult> Post([FromBody] CreateCinemaModel cinemaModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CinemaDomainModel domainModel = new CinemaDomainModel { Name = cinemaModel.Name }; CreateCinemaResultModel createCinemaResultModel; try { createCinemaResultModel = await _cinemaService.AddCinema(domainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (!createCinemaResultModel.IsSuccessful) { ErrorResponseModel errorResponse = new ErrorResponseModel() { ErrorMessage = createCinemaResultModel.ErrorMessage, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } return(Created("auditoriums//" + createCinemaResultModel.Cinema.Id, createCinemaResultModel)); }
public ActionResult Create(Models.Cinema model) { if (ModelState.IsValid) { if (!cinemaService.ExistsCinema(model.CinemaCity)) { var dbModel = new Domain.Cinema(); dbModel.InjectFrom(model); cinemaService.AddCinema(dbModel); TempData["message"] = string.Format("{0} has been saved", model.CinemaCity); } else { ModelState.AddModelError("CinemaCity", "Cant add a cinema that is already in the database!"); //transform the object //unitOfWork.Commit return(View(model)); } return(RedirectToAction("Index")); } return(View(model)); }