public async Task <IActionResult> CreateConfirmed(Movie movie) { Dictionary <string, string[]> ModelStateErrors = new Dictionary <string, string[]>(); if (ModelState.IsValid) { try { //_context.Add(movie); _movieServie.Add(movie); await _movieServie.Save(); } catch (DbUpdateConcurrencyException ex) { return(Content(ex.Message.ToString())); } } else { ModelStateErrors = ModelState.Where(x => x.Value.Errors.Count > 0) .ToDictionary(k => k.Key, k => k.Value.Errors.Select(e => e.ErrorMessage).ToArray()); } TempData["StateError"] = ModelStateErrors; return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([FromBody] MovieModel movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var realisator = await _service.GetRealisatorById(movie.RealisatorId); if (realisator == null) { return(NotFound()); } var actor = await _service.GetActorById(movie.ActorId); if (actor == null) { return(NotFound()); } var model = new Movie { BoxDate = DateTime.Now, Cover = movie.Cover, Title = movie.Title, Realisator = realisator, Actors = new List <Actor>() }; model.Actors.Add(actor); await _service.Add(model); return(Ok(movie)); }
public IActionResult Create([Bind("Id,Title,ReleaseDate,Genre,Price,Rating,Sales")] MovieViewModel movie) { if (ModelState.IsValid) { _moviesService.Add(movie); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <ActionResult <MovieDto> > CreateMovie([FromBody] AddMovieDto movie) { if (string.IsNullOrEmpty(movie.Title)) { return(BadRequest(new ErrorMessage("Title cannot be empty"))); } if (movie.Duration <= 0) { return(BadRequest(new ErrorMessage("Duration must be longer than 0 minutes"))); } var newMovie = await _moviesService.Add(movie); return(Ok(newMovie)); }
public ActionResult Add(Models.Movies.AddViewModel model, HttpPostedFileBase banner) { if (!ModelState.IsValid) { //select lists model.SeanceSelectList = GetSeanceSelectList(SessionHelper.CurrentUser.UserToken); model.SalonSelectList = GetSalonSelectList(SessionHelper.CurrentUser.UserToken); model.MoviesTypeSelectList = GetMoviesTypenSelectList(SessionHelper.CurrentUser.UserToken); return(View(model)); } WebImage img = new WebImage(banner.InputStream); FileInfo fotoinfo = new FileInfo(banner.FileName); string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension; img.Resize(150, 150); img.Save("~/Uploads/MoviesBanner/" + newfoto); Business.Models.Movies.Movies movies = new Business.Models.Movies.Movies(); movies.SeanceId = model.SeanceId; movies.SalonId = model.SalonId; movies.Name = model.Name; movies.TypeId = model.TypeId; movies.Director = model.Director; movies.Banner = "/Uploads/MoviesBanner/" + newfoto; var apiResponseModel = _moviesService.Add(SessionHelper.CurrentUser.UserToken, movies); if (apiResponseModel.ResultStatusCode == ResultStatusCodeStatic.Success) { return(RedirectToAction(nameof(MoviesController.List))); } else { //select lists model.SeanceSelectList = GetSeanceSelectList(SessionHelper.CurrentUser.UserToken); model.SalonSelectList = GetSalonSelectList(SessionHelper.CurrentUser.UserToken); model.MoviesTypeSelectList = GetMoviesTypenSelectList(SessionHelper.CurrentUser.UserToken); ViewBag.ErrorMessage = apiResponseModel.ResultStatusMessage != null ? apiResponseModel.ResultStatusMessage : "Not Saved"; return(View(model)); } }
public ApiResponseModel <Data.Entity.Movies> Add([FromBody] AddRequestModel requestModel) { var responseModel = new ApiResponseModel <Data.Entity.Movies>(); try { var record = new Data.Entity.Movies(); record.SeanceId = requestModel.SeanceId; record.SalonId = requestModel.SalonId; record.Name = requestModel.Name; record.TypeId = requestModel.TypeId; record.Director = requestModel.Director; record.Banner = requestModel.Banner; record.IsDeleted = false; var dbResult = _moviesService.Add(record); if (dbResult > 0) { responseModel.Data = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor responseModel.ResultStatusCode = ResultStatusCodeStatic.Success; responseModel.ResultStatusMessage = "Success"; } else { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = "CouldNotBeSaved"; } } catch (Exception ex) { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = ex.Message; } return(responseModel); }