// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { var newFilm = new Film(); if (selectedCategories != null) { newFilm.FilmCategories = new List <FilmCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new FilmCategory { CategoryID = int.Parse(cat) }; newFilm.FilmCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Film>( newFilm, "Film", i => i.Title, i => i.Length, i => i.Price, i => i.ReleaseDate, i => i.DirectorID)) { _context.Film.Add(newFilm); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newFilm); return(Page()); }
public FilmCollection PostFilmCollection(FilmCollection col) { var original = db.FilmCollections.Find(col.FilmCollectionID); if (original == null) { db.FilmCollections.Add(col); db.SaveChanges(); FilmCategory cat = db.FilmCategories.Where(fc => fc.Description == Film.SHORT_COLLECTION).FirstOrDefault(); Film newFilm = new Film() { Title = col.Name, Showing = DateTime.Parse("03/06/2021 11:00"), FilmCategoryID = cat.FilmCategoryID, FilmCollectionID = col.FilmCollectionID }; db.Films.Add(newFilm); db.SaveChanges(); col.FilmID = newFilm.FilmID; col.Film = newFilm; db.SaveChanges(); return(col); } original.Name = col.Name; db.SaveChanges(); return(original); }
public ActionResult Create(FilmCategoryViewModel filmCategory) { if (ModelState.IsValid) { //cập nhật thời gian, tên ảnh, người thực hiện, mã của sản phẩm - thiếu người thực hiện filmCategory.CreatedDate = filmCategory.UpdatedDate = DateTime.Now; //Phân quyền //filmCategory.CreatedBy = filmCategory.UpdatedBy = USER_ID; //thêm vào database và lưu kết quả FilmCategory result = new FilmCategory(); result.UpdateFilmCategory(filmCategory); var resultFilmCategory = _filmCategoryService.Add(result); _filmCategoryService.SaveChanges(); if (resultFilmCategory == null) { return(RedirectToAction("Index", "FilmCategory")); } else { //fileUpload.SaveAs(pathImage); SetAlert("Thêm thể loại phim thành công", CommonConstrants.SUCCESS_ALERT); return(RedirectToAction("Index", "FilmCategory")); } } return(View()); }
public async Task <IActionResult> PutFilmCategory(int id, FilmCategory filmCategory) { if (id != filmCategory.FilmCategoryID) { return(BadRequest()); } _context.Entry(filmCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <FilmCategory> > PostFilmCategory(FilmCategory filmCategory) { _context.FilmCategories.Add(filmCategory); await _context.SaveChangesAsync(); //return CreatedAtAction("GetFilmCategory", new { id = filmCategory.FilmCategoryID }, filmCategory); return(CreatedAtAction(nameof(GetFilmCategory), new { id = filmCategory.FilmCategoryID }, filmCategory)); }
private void filmCategories_SelectedIndexChanged(object sender, EventArgs e) { ComboBox box = (ComboBox)sender; FilmCategory cat = (FilmCategory)box.SelectedItem; if (cat != null) { film.FilmCategoryID = cat.FilmCategoryID; } }
public static void UpdateFilmCategory(this FilmCategory filmCategory, FilmCategoryViewModel filmCategoryVm) { filmCategory.FilmCategoryName = filmCategoryVm.FilmCategoryName; filmCategory.FilmCategoryDescrip = filmCategoryVm.FilmCategoryDescrip; filmCategory.CreatedDate = filmCategoryVm.CreatedDate; filmCategory.CreatedBy = filmCategoryVm.CreatedBy; filmCategory.UpdatedDate = filmCategoryVm.UpdatedDate; filmCategory.UpdatedBy = filmCategoryVm.UpdatedBy; filmCategory.MetaKeyword = filmCategoryVm.MetaKeyword; filmCategory.MetaDescription = filmCategoryVm.MetaDescription; }
private void filmCategories_SelectedIndexChanged(object sender, EventArgs e) { ListBox box = (ListBox)sender; FilmCategory cat = (FilmCategory)box.SelectedItem; filmCategory.Text = cat.Description; isViewable.Checked = cat.IsViewable; newCategory = false; saveCategory.Enabled = false; saveCategory.Text = "Update"; }
public ActionResult Delete(int?id) { if (id != null) { FilmCategory filmCategory = _filmCategoryService.Find((int)id); if (filmCategory == null) { return(HttpNotFound()); } _filmCategoryService.Delete(filmCategory); _filmCategoryService.SaveChanges(); SetAlert("Xóa 1 thể loại phim thành công", CommonConstrants.SUCCESS_ALERT); return(RedirectToAction("Index")); } return(RedirectToAction("Index", "FilmCategory")); }
public ActionResult Edit(int?id) { if (id != null) { FilmCategory filmCategory = _filmCategoryService.Find((int)id); if (filmCategory == null) { return(HttpNotFound()); } var resultVm = Mapper.Map <FilmCategory, FilmCategoryViewModel>(filmCategory); TempData["filmCategoryItem"] = resultVm; return(View(resultVm)); } return(RedirectToAction("Index", "FilmCategory")); }
public FilmCategory PostFilmCategory(FilmCategory cat) { var original = db.FilmCategories.Find(cat.FilmCategoryID); if (original == null) { db.FilmCategories.Add(cat); db.SaveChanges(); return(cat); } original.Description = cat.Description; original.IsViewable = cat.IsViewable; db.SaveChanges(); return(original); }
public ActionResult Edit(FilmCategory filmCategory) { if (ModelState.IsValid) { //filmCategory.UpdatedBy var result = (FilmCategoryViewModel)TempData["filmCategoryItem"]; filmCategory.FilmCategoryID = result.FilmCategoryID; filmCategory.UpdatedDate = DateTime.Now; filmCategory.UpdatedBy = result.UpdatedBy; filmCategory.MetaDescription = result.MetaDescription; filmCategory.MetaKeyword = result.MetaKeyword; _filmCategoryService.Update(filmCategory); _filmCategoryService.SaveChanges(); SetAlert("Sửa thể loại phim thành công", CommonConstrants.SUCCESS_ALERT); return(RedirectToAction("Index")); } return(View(filmCategory)); }
private async void saveCategory_Click(object sender, EventArgs e) { FilmCategory cat = null; if (newCategory) { cat = new FilmCategory() { Description = filmCategory.Text, IsViewable = isViewable.Checked }; catBinding.Add(cat); } else { cat = (FilmCategory)filmCategories.SelectedItem; cat.Description = filmCategory.Text; cat.IsViewable = isViewable.Checked; } var newcat = await _apiService.PostFilmCategory(cat); if (newCategory) { cat = catBinding.Where(fc => fc.FilmCategoryID == 0).First(); cat.FilmCategoryID = newcat.FilmCategoryID; cat.Description = newcat.Description; filmCategories.SelectedIndex = filmCategories.Items.Count - 1; } else { catBinding.Where(fc => fc.FilmCategoryID == cat.FilmCategoryID).First().Description = newcat.Description; catBindingSource.ResetBindings(true); } saveCategory.Enabled = false; }
public ActionResult FilmEdit(FormCollection fc, HttpPostedFileBase UploadFile) { Film film = new Models.Film(); TryUpdateModel <Film>(film, fc); if (UploadFile != null) { var fileName = Path.GetFileName(UploadFile.FileName); var filePath = Server.MapPath("/Content/Images/Films"); string savedFileName = Path.Combine(filePath, fileName); UploadFile.SaveAs(savedFileName); film.Imagefile = fileName; } if (ModelState.IsValid) { dbcon.Open(); int intresult = Film.CUFilm(dbcon, "update", film); FilmCategory.UpdateCategories(dbcon, fc); dbcon.Close(); } return(RedirectToAction("FilmList", "Admin")); }
public FilmCategory Add(FilmCategory filmCategory) { return(_filmCategoryRepository.Add(filmCategory)); }
public static string GetCode(this FilmCategory category) => category.GetAttribute <CategoryAttribute>()?.Code;
public void Update(FilmCategory filmCategory) { _filmCategoryRepository.Update(filmCategory); }
public FilmCategory Delete(FilmCategory filmCategory) { return(_filmCategoryRepository.Delete(filmCategory)); }
public async Task <FilmCategory> PostFilmCategory(FilmCategory cat) { FilmCategory newCat = await ApiComplexPost <FilmCategory, FilmCategory>(BasePath + "api/Admin/PostFilmCategory", cat); return(newCat); }
public static string GetDisplayName(this FilmCategory category) => category.GetAttribute <CategoryAttribute>()?.DisplayName ?? category.ToString();
public static bool IsRating(this FilmCategory category) => category.GetAttribute <CategoryAttribute>()?.IsRating ?? false;
public static bool IsSpecialScreening(this FilmCategory category) => category.GetAttribute <CategoryAttribute>()?.IsSpecialScreening ?? false;
public static bool IsPeopleTypeScreening(this FilmCategory category) => category.GetAttribute <CategoryAttribute>()?.IsPeopleTypeScreening ?? false;