public async Task EditAsync(MovieCategoryModel model) { if (await _context.MovieCategories.AnyAsync(x => x.Description.Trim().ToLower() == model.Description.Trim().ToLower() && x.Id != model.Id)) { throw new DuplicatedExcpection("Cadastrada já cadastrada"); } var category = await _context.MovieCategories.FirstOrDefaultAsync(x => x.Id == model.Id); if (category == null) { throw new NotFoundException("Categoria não encontrada"); } category.Description = model.Description.Trim(); try { _context.MovieCategories.Update(category); await _context.SaveChangesAsync(); } catch { throw new Exception("Não foi possível cadastrar essa categoria"); } }
public IActionResult Details(int id) { MovieCategoryModel model = new MovieCategoryModel(); model.Categories = CategoryRepository.Categories; model.Movie = MovieRepository.GetById(id); return(View(model)); }
public IActionResult Index() { //ProductRepository.Movies //CategoryRepository.Categories MovieCategoryModel model = new MovieCategoryModel(); model.Categories = CategoryRepository.Categories; model.Movies = MovieRepository.Movies; return(View(model)); }
public IActionResult Index(int?id) { MovieCategoryModel model = new MovieCategoryModel(); model.Categories = CategorRepository.Categories; model.Movies = MovieRepository.Movies; if (id != null) { model.Movies = MovieRepository.Movies; } return(View(model)); }
public async Task <IActionResult> Edit(MovieCategoryModel model) { try { await _appmovieCategory.EditAsync(model); ViewBag.Success = true; ViewBag.Message = "Categoria editada com sucesso"; return(View(model)); } catch (Exception e) { ViewBag.Success = false; ViewBag.Message = e.Message; return(View(model)); } }
public async Task <IActionResult> Register(MovieCategoryModel model) { try { await _appmovieCategory.RegisterAsync(model); TempData["Success"] = true; TempData["Message"] = "Categoria Cadastrada com sucesso"; return(RedirectToAction("Register")); } catch (Exception e) { ViewBag.Success = false; ViewBag.Message = e.Message; return(View(model)); } }
public async Task <IActionResult> Delete(MovieCategoryModel model) { try { await _appmovieCategory.DeleteAsync(model); TempData["Success"] = true; TempData["Message"] = "Categoria deletada com sucesso"; return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.Success = false; ViewBag.Message = e.Message; return(View(model)); } }
public async Task DeleteAsync(MovieCategoryModel model) { var category = await _context.MovieCategories.FirstOrDefaultAsync(x => x.Id == model.Id); if (category == null) { throw new NotFoundException("Categoria não encontrada"); } try { _context.MovieCategories.Remove(category); await _context.SaveChangesAsync(); } catch { throw new Exception("Não foi possível deletar essa categoria"); } }
public async Task RegisterAsync(MovieCategoryModel model) { if (_context.MovieCategories.Any(x => x.Description.Trim().ToLower() == model.Description.Trim().ToLower())) { throw new DuplicatedExcpection("Categoria já cadastrada"); } var moviecategory = new MovieCategory(model.Description.Trim()); try { await _context.MovieCategories.AddAsync(moviecategory); await _context.SaveChangesAsync(); } catch { throw new Exception("Não foi possível cadastrar essa categoria"); } }
// GET: Movies public async Task <IActionResult> Index(string movieCategory, string searchString) { IQueryable <string> categoryQuery = from m in _context.Movie orderby m.Category select m.Category; var movies = from m in _context.Movie select m; if (!String.IsNullOrEmpty(searchString)) { movies = movies.Where(s => s.Title.Contains(searchString)); } if (!String.IsNullOrEmpty(movieCategory)) { movies = movies.Where(s => s.Category.Contains(movieCategory)); } var movieCategoryModel = new MovieCategoryModel { Categories = new SelectList(await categoryQuery.Distinct().ToListAsync()), Movies = await movies.ToListAsync() }; return(View(movieCategoryModel)); //return View(await movies.ToListAsync()); }