/// <summary> /// The Creates entity for FilmCategoryViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="FilmCategoryViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse{FilmCategoryViewModel}"/>.</returns> public SimpleResponse <FilmCategoryViewModel> Create(FilmCategoryViewModel model) { var response = new SimpleResponse <FilmCategoryViewModel>(); try { var validation = model.Validate(); if (validation.HasError) { return(new SimpleResponse <FilmCategoryViewModel> { Data = model, ResponseCode = BusinessResponseValues.ValidationErrorResult, ResponseMessage = validation.AllValidationMessages }); } using (var context = new PublicCoreDbContext()) { var entity = Map <FilmCategoryViewModel, FilmCategory>(model); context.FilmCategory.Add(entity); response.ResponseCode = context.SaveChanges(); } } catch (Exception ex) { response.ResponseCode = BusinessResponseValues.InternalError; response.ResponseMessage = "Ekleme iþleminde hata oluþtu."; DayLogger.Error(ex); } return(response); }
public IHttpActionResult UpdatePost(FilmCategoryViewModel model) { var response = new SimpleResponse(); response = iFilmCategoryBusiness.Update(model); return(Json(response)); }
/// <summary> /// Deletes entity for FilmCategoryViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="FilmCategoryViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse"/>.</returns> public SimpleResponse Delete(FilmCategoryViewModel model) { var response = new SimpleResponse(); try { using (var context = new PublicCoreDbContext()) { var entity = context.FilmCategory.SingleOrDefault(q => q.FilmId == model.FilmId && q.CategoryId == model.CategoryId); if (entity == null || entity == default(FilmCategory)) { response.ResponseCode = BusinessResponseValues.NullEntityValue; response.ResponseMessage = "Kayýt bulunamadý."; return(response); } context.FilmCategory.Remove(entity); response.ResponseCode = context.SaveChanges(); } } catch (Exception ex) { response.ResponseCode = BusinessResponseValues.InternalError; response.ResponseMessage = "Silme iþleminde hata oluþtu."; DayLogger.Error(ex); } return(response); }
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 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; }
public IActionResult UpdatePost(FilmCategoryViewModel model) { var response = iFilmCategoryBusiness.Update(model); if (response.ResponseCode > 0) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, response.ResponseMessage); return(View("Edit", model)); } }
/// <summary> /// Updates entity for FilmCategoryViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="FilmCategoryViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse"/>.</returns> public SimpleResponse Update(FilmCategoryViewModel model) { var response = new SimpleResponse(); try { var validation = model.Validate(); if (validation.HasError) { return(new SimpleResponse { ResponseCode = BusinessResponseValues.ValidationErrorResult, ResponseMessage = validation.AllValidationMessages }); } using (var context = new PublicCoreDbContext()) { var entity = context.FilmCategory.SingleOrDefault(q => q.FilmId == model.FilmId && q.CategoryId == model.CategoryId); if (entity == null || entity == default(FilmCategory)) { response.ResponseCode = BusinessResponseValues.NullEntityValue; response.ResponseMessage = "Kayýt bulunamadý."; return(response); } MapTo(model, entity); context.FilmCategory.Attach(entity); // context.Entry(entity).State = EntityState.Modified; response.ResponseCode = context.SaveChanges(); } } catch (Exception ex) { response.ResponseCode = BusinessResponseValues.InternalError; response.ResponseMessage = "Güncelleme iþleminde hata oluþtu."; DayLogger.Error(ex); } return(response); }
public SimpleResponse Update(FilmCategoryViewModel model) { var response = iFilmCategoryBusiness.Update(model); return(response); }
public IActionResult Create() { var model = new FilmCategoryViewModel(); return(View("Create", model)); }