public async Task <IActionResult> CreateOrEdit(int?id = null) { if (id == null) { return(View(new MovieViewModel { ActionName = "Create" })); } var result = await _movieService.GetMovie(id.Value); if (!result.IsSuccess) { return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = result.IsSuccess })); } var movie = result.Data; if (!await _userManager.CheckEditPermissionAsync(User, movie)) { return(Forbid()); } var model = MovieViewModel.FromModel(movie); model.ActionName = "Edit"; return(View(model)); }
public async Task <MoviePageViewModel> GetMoviePage(int page) { IQueryable <Movie> source = _db.Movies.Include(m => m.Downloader); var count = await source.CountAsync(); if (count == 0) { return(new MoviePageViewModel(pageNumber: 1, MOVIES_PER_PAGE, totalPages: 1, new List <MovieViewModel>())); } var totalPages = (int)Math.Ceiling(count / (double)MOVIES_PER_PAGE); if (page < 1) { page = 1; } else if (page > totalPages) { page = totalPages; } var movies = await source .Skip((page - 1) *MOVIES_PER_PAGE) .Take(MOVIES_PER_PAGE) .Select(m => MovieViewModel.FromModel(m, null)) .ToListAsync(); var pageViewModel = new MoviePageViewModel(page, MOVIES_PER_PAGE, totalPages, movies); return(pageViewModel); }
public async Task <IActionResult> Delete(int id) { var result = await _movieService.GetMovie(id); if (!result.IsSuccess) { return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = false })); } var movie = result.Data; if (!await _userManager.CheckEditPermissionAsync(User, movie)) { return(Forbid()); } return(View(MovieViewModel.FromModel(result.Data))); }
public async Task <IActionResult> Details(int id, bool showSuccessMessage = false) { var result = await _movieService.GetMovie(id); if (!result.IsSuccess) { return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = result.IsSuccess })); } var movie = result.Data; var isCurrentUserDownloader = await _userManager.CheckEditPermissionAsync(User, movie); var model = MovieViewModel.FromModel(movie, isCurrentUserDownloader); if (showSuccessMessage) { model.Message = OperationResultHelper.GetMessage(isSuccess: true); model.IsSuccessMessage = true; } return(View(model)); }