public IActionResult GetMovie(OrderDetailsVM getMovie) { ResultsWrapperHelper helper = _movieService.MovieById(getMovie); if (!string.IsNullOrEmpty(helper.Message)) { return(RedirectToAction("GetMovie", new { error = helper.Message })); } if (!ModelState.IsValid) { return(View("GetMovie", getMovie)); } return(View("BuyingComplete")); }
public ResultsWrapperHelper UploadMovie(UploadMovieVM uploadMovieVM) { var helper = new ResultsWrapperHelper(); helper.UploadMovieVM = uploadMovieVM; var allUsers = _userRepository.GetAll(); var allMovies = _movieRepository.GetAll(); if (string.IsNullOrWhiteSpace(uploadMovieVM.Email)) { helper.Message = "Enter correnct Email"; return(helper); } var oldUser = allUsers.FirstOrDefault(u => u.Email.ToLower().Trim() == uploadMovieVM.Email.ToLower().Trim()); if (oldUser == null) { helper.Message = "You are Email is not correct"; return(helper); } if (oldUser.TypeOfUser != TypeOfUser.AdminUser) { helper.Message = "You are not Admin"; return(helper); } if (string.IsNullOrWhiteSpace(uploadMovieVM.Title)) { helper.Message = "Enter Title"; return(helper); } var oldmovie = allMovies.FirstOrDefault(m => m.Title.ToLower().Trim() == uploadMovieVM.Title.ToLower().Trim()); if (oldmovie != null) { helper.Message = "The movie is already uploaded... exists";; return(helper); } var newMovie = MapperHelper.MapUploadMovieVmToMovieModel(uploadMovieVM); _movieRepository.AddEntity(newMovie); return(helper); }
public IActionResult UploadMovie(UploadMovieVM uploadMovie) { if (!ModelState.IsValid) { return(View("UploadMovie", uploadMovie)); } ResultsWrapperHelper helper = _movieService.UploadMovie(uploadMovie); if (!string.IsNullOrEmpty(helper.Message)) { TempData["Error"] = helper.Message; return(RedirectToAction("UploadMovie")); } return(View("UploadingComplete")); }
public ResultsWrapperHelper MovieById(OrderDetailsVM orderDetails) { var movie = _movieRepository.GetById(orderDetails.IdOfMovie); var helper = new ResultsWrapperHelper(); helper.OrderDetailsVM = orderDetails; if (movie == null) { helper.Message = "There is no movie like that, try again"; return(helper); } var user = MapperHelper.MapOrderDetailsVmToUserModel(orderDetails); if (string.IsNullOrEmpty(user.Email)) { helper.Message = "You must have valid email"; return(helper); } if (_userRepository.GetAll() .SingleOrDefault(u => u.Email.ToLower().Trim() == user.Email.ToLower().Trim()) == null) { _userRepository.AddEntity(user); } var stats = new OrderMovieStatsHistory() { MovieId = movie.Id, UserId = user.Id }; _orderRepository.AddEntity(stats); return(helper); }