//[Authorize(Policy = "RequireAdministratorRole")] public async Task <IActionResult> UpdatePhim([FromRoute] int id, [FromBody] PhimModel formdata) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var findPhim = _db.Phims.FirstOrDefault(p => p.MaPhim == id); if (findPhim == null) { return(NotFound()); } // If the product was found findPhim.TenPhim = formdata.TenPhim; findPhim.SoTap = formdata.SoTap; findPhim.Nam = formdata.Nam; findPhim.Anh = formdata.Anh; findPhim.NoiDung = formdata.NoiDung; findPhim.LuotXem = formdata.LuotXem; _db.Entry(findPhim).State = EntityState.Modified; await _db.SaveChangesAsync(); return(Ok(new JsonResult("Update thành công phim có mã " + id + ""))); }
public async Task <IActionResult> Edit(int id, [Bind("IDPhim,IDPhong,AnhPhim,TenPhim,TenDienVien,TenNgonNgu,TheLoai,TenPhuDe,DaoDien,KhoiChieu,ThoiLuong,Rated,TrangThai")] PhimModel phimModel) { if (id != phimModel.IDPhim) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(phimModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(phimModel.IDPhim)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDPhong"] = new SelectList(_context.Phong, "IDPhong", "IDPhong", phimModel.IDPhong); return(View(phimModel)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Ten_phim,Hinh_anh,Thoi_luong,Luot_xem,Gia_ve,Lich_Chieu,Da_xoa")] PhimModel phimModel) { if (id != phimModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(phimModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(phimModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(phimModel)); }
public async Task <IActionResult> PutPhimModel(int id, PhimModel phimModel) { if (id != phimModel.IdPhim) { return(BadRequest()); } _context.Entry(phimModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,TenPhim,ThoiLuong,DaoDien,DienVien,QuocGia,Mota,HinhAnh,Trailer,NgayPhatHanh,MaLoai,TrangThai")] PhimModel phimModel, IFormFile ful) { ViewBag.lstLoaiPhim_Active = (from p in _context.tb_LoaiPhim where p.TrangThai == true select p).ToList(); if (ModelState.IsValid) { _context.Add(phimModel); await _context.SaveChangesAsync(); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/Phim", phimModel.Id + "." + ful.FileName.Split(".") [ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.HinhAnh = phimModel.Id + "." + ful.FileName.Split(".") [ful.FileName.Split(".").Length - 1]; if (phimModel.NgayPhatHanh > DateTime.Now) { phimModel.TrangThai = 2; } else { phimModel.TrangThai = 1; } _context.Update(phimModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["MaLoai"] = new SelectList(_context.tb_LoaiPhim, "Id", "TenLoai", phimModel.MaLoai); return(View(phimModel)); }
public async Task <ActionResult <PhimModel> > PostPhimModel(PhimModel phimModel) { _context.phimModels.Add(phimModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPhimModel", new { id = phimModel.IdPhim }, phimModel)); }
public async Task <IActionResult> Create([Bind("ID,Ten_phim,Hinh_anh,Thoi_luong,Luot_xem,Gia_ve,Lich_Chieu,Da_xoa")] PhimModel phimModel) { if (ModelState.IsValid) { _context.Add(phimModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(phimModel)); }
public async Task <IActionResult> Create([Bind("IDPhim,IDPhong,AnhPhim,TenPhim,TenDienVien,TenNgonNgu,TheLoai,TenPhuDe,DaoDien,KhoiChieu,ThoiLuong,Rated,TrangThai")] PhimModel phimModel) { if (ModelState.IsValid) { _context.Add(phimModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDPhong"] = new SelectList(_context.Phong, "IDPhong", "IDPhong", phimModel.IDPhong); return(View(phimModel)); }
// GET: Admin/Phim public async Task <IActionResult> Index(string Search) { PhimModel phim = null; if (Search != null) { ViewBag.ListDuLieu = _context.Phim.Include(p => p.loaiPhim).Where(s => s.TenPhim.Contains(Search)).ToList(); } else { ViewBag.ListDuLieu = _context.Phim.Include(p => p.loaiPhim).ToList(); } //var dPContext = _context.Phim.Include(p => p.loaiPhim); //return View(await dPContext.ToListAsync()); return(View()); }
public async Task <IActionResult> Edit(int id, [Bind("IdPhim,TenPhim,ThoiLuong,HinhAnh,Mota,MaLoaiPhim")] PhimModel phimModel, IFormFile ful, string hinhanh) { if (id != phimModel.IdPhim) { return(NotFound()); } if (ModelState.IsValid) { try { var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/ImageAdmin/ImgPhim", hinhanh); System.IO.File.Delete(parth); if (ful == null) { phimModel.HinhAnh = hinhanh; } else { parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/ImageAdmin/ImgPhim", phimModel.IdPhim + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.HinhAnh = phimModel.IdPhim + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; } _context.Update(phimModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(phimModel.IdPhim)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaLoaiPhim"] = new SelectList(_context.loaiPhimModels, "IdLoaiPhim", "TenLoaiPhim", phimModel.MaLoaiPhim); return(View(phimModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TenPhim,AnhPhim,ThoiLuong,MoTa,TinhTrang,IdLoaiPhim")] PhimModel phimModel, IFormFile ful) { if (id != phimModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(phimModel); if (ful != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AnhPhim", phimModel.AnhPhim); System.IO.File.Delete(path); path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AnhPhim", phimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.AnhPhim = phimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(phimModel); await _context.SaveChangesAsync(); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(phimModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdLoaiPhim"] = new SelectList(_context.LoaiPhim, "Id", "TenLoai", phimModel.IdLoaiPhim); return(View(phimModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TenPhim,ThoiLuong,DaoDien,DienVien,QuocGia,Mota,HinhAnh,Trailer,NgayPhatHanh,MaLoai,TrangThai")] PhimModel phimModel, IFormFile ful) { if (id != phimModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(phimModel); if (ful != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/Phim", phimModel.HinhAnh); System.IO.File.Delete(path); path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/Phim", phimModel.Id + "." + ful.FileName.Split(".") [ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.HinhAnh = phimModel.Id + "." + ful.FileName.Split(".") [ful.FileName.Split(".").Length - 1]; _context.Update(phimModel); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhimModelExists(phimModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["MaLoai"] = new SelectList(_context.tb_LoaiPhim, "Id", "TenLoai", phimModel.MaLoai); return(View(phimModel)); }
//[Authorize(Policy = "RequireAdministratorRole")] public async Task <IActionResult> AddPhim([FromBody] PhimModel formdata) { var newphim = new PhimModel { TenPhim = formdata.TenPhim, SoTap = formdata.SoTap, Nam = formdata.Nam, Anh = formdata.Anh, NoiDung = formdata.NoiDung, LuotXem = formdata.LuotXem }; await _db.Phims.AddAsync(newphim); await _db.SaveChangesAsync(); return(Ok(new JsonResult("Thêm thành công"))); }
public async Task <IActionResult> Create([Bind("Id,TenPhim,AnhPhim,ThoiLuong,MoTa,TinhTrang,IdLoaiPhim")] PhimModel phimModel, IFormFile ful) { if (ModelState.IsValid) { _context.Add(phimModel); await _context.SaveChangesAsync(); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AnhPhim", phimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.AnhPhim = phimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(phimModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdLoaiPhim"] = new SelectList(_context.LoaiPhim, "Id", "TenLoai", phimModel.IdLoaiPhim); return(View(phimModel)); }
public async Task <IActionResult> Create([Bind("IdPhim,TenPhim,ThoiLuong,HinhAnh,Mota,MaLoaiPhim")] PhimModel phimModel, IFormFile ful) { if (ModelState.IsValid) { _context.Add(phimModel); await _context.SaveChangesAsync(); var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/ImageAdmin/ImgPhim", phimModel.IdPhim + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } phimModel.HinhAnh = phimModel.IdPhim + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(phimModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.TypeFilm = _context.loaiPhimModels.ToList(); return(View(phimModel)); }