public ActionResult CategoryDelete(long categoryId) { CT_CATEGORY deletedCategory = repository.DeleteCategory(categoryId); if (deletedCategory != null) { TempData["message"] = string.Format("{0} был удален", deletedCategory.Code); } return(RedirectToAction("Categories")); }
public CT_CATEGORY DeleteCategory(long categoryId) { CT_CATEGORY dbEntry = context.CT_CATEGORY.Where(x => x.CategoryId == categoryId).Single(); //.Find(LoadRuleId); if (dbEntry != null) { context.CT_CATEGORY.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public ActionResult CategoryEdit(CT_CATEGORY category) { if (ModelState.IsValid) { repository.SaveCategory(category); TempData["message"] = string.Format("{0} сохранено", category.Code); return(RedirectToAction("Categories")); } else { // что-то не так с значениями данных (there is something wrong with the data values) return(View(category)); } }
public void SaveCategory(CT_CATEGORY category) { category.DateLoad = DateTime.Now; if (category.CategoryId == 0) { context.CT_CATEGORY.Add(category); } else { CT_CATEGORY dbEntry = context.CT_CATEGORY.Where(x => x.CategoryId == category.CategoryId).Single(); //.Find(loadRule.LoadRuleId); if (dbEntry != null) { dbEntry.Code = category.Code; dbEntry.Name = category.Name; dbEntry.Ord = category.Ord; dbEntry.DateLoad = category.DateLoad; } } context.SaveChanges(); }
public ViewResult CategoryEdit(long categoryId) { CT_CATEGORY category = repository.Categories.Where(p => p.CategoryId == categoryId).FirstOrDefault(); return(View(category)); }