// create category public async Task <CategoryViewsModels> Create(CategoryViewsModels addCategory) { var category = new Category() { CategoryName = addCategory.CategoryName, }; _context.Categories.Add(category); await _context.SaveChangesAsync(); return(addCategory); }
public async Task <IActionResult> Edit(int id, CategoryViewsModels editCategory) { if (ModelState.IsValid) { if (id == editCategory.Id) { await _category.EditCategory(id, editCategory); TempData["EditSuccessfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly"); return(RedirectToAction("Index")); } } ViewData["EditFailure"] = _categoryLocalizer.GetLocalizedString("err_EditFailure"); return(View()); }
public async Task <IActionResult> Create(CategoryViewsModels category) { if (ModelState.IsValid) { var addCategory = await _category.Create(category); if (addCategory != null) { TempData["AddSuccessfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly"); return(RedirectToAction("Index")); } } ViewData["AddFailure"] = _categoryLocalizer.GetLocalizedString("err_AddFailure"); return(View(category)); }
public async Task <IActionResult> Edit(CategoryViewsModels editCategory) { if (ModelState.IsValid) { var category = await _category.EditCategoryAsync(editCategory); if (category) { TempData["Successfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly").ToString(); return(RedirectToAction("Index")); } TempData["Failure"] = _localizer.GetLocalizedString("err_EditFailure").ToString(); return(View(editCategory)); } return(View(editCategory)); }
public async Task <IActionResult> Create(CategoryViewsModels category) { if (ModelState.IsValid) { var addCategory = await _category.AddCategoryAsync(category); if (addCategory) { TempData["Successfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly").ToString(); return(RedirectToAction("Index")); } ViewData["EditFailure"] = _localizer.GetLocalizedString("err_AddFailure"); Log.Error("Add category error "); return(View(category)); } Log.Error("Add category error "); return(View(category)); }
//post edit category public async Task <CategoryViewsModels> EditCategory(int?id, CategoryViewsModels editCategory) { try { var category = _context.Categories.Find(id); category.CategoryName = editCategory.CategoryName; _context.Categories.Update(category); await _context.SaveChangesAsync(); return(editCategory); } catch (Exception e) { Console.WriteLine(e); return(null); } }
/// <summary> /// post edit category /// </summary> /// <param name="editCategory">CategoryViewsModels</param> /// <returns></returns> public async Task <bool> EditCategoryAsync(CategoryViewsModels editCategory) { try { var category = await _context.Categories.FindAsync(editCategory.Id); category.CategoryName = editCategory.CategoryName; _context.Categories.Update(category); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { Log.Error("Edit Category Async Error: {0}", e.Message); return(false); } }
//post edit category public async Task <bool> EditCategoryAsync(CategoryViewsModels editCategory) { try { var category = await _context.Categories.FindAsync(editCategory.Id); category.CategoryName = editCategory.CategoryName; _context.Categories.Update(category); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
/// <summary> /// create category service /// </summary> /// <param name="addCategory">CategoryViewsModels</param> /// <returns>true || false</returns> public async Task <bool> AddCategoryAsync(CategoryViewsModels addCategory) { try { var category = new Category() { CategoryName = addCategory.CategoryName }; _context.Categories.Add(category); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { Log.Error("Add Category Async Error: {0}", e.Message); return(false); } }
// create category public async Task <bool> AddCategoryAsync(CategoryViewsModels addCategory) { try { var category = new Category() { CategoryName = addCategory.CategoryName, }; _context.Categories.Add(category); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }