public IActionResult InsertCategory(CategoryVM categoryVM) { User currentAdmin = HttpContext.Session.Get <User>("currentUser"); Category category = new Category { CategoryName = categoryVM.CategoryName, Description = categoryVM.Overview }; if (category != null) { try { categoryBLL.Add(category); this._logger.LogInformation($"AdminID : {currentAdmin.ID} is created CategoryID : {category.ID}."); } catch (Exception) { throw; } } else { ViewBag.Message = "Check your datas."; } return(View("Index")); }
public ActionResult Add(string categoryName, int isService) { // 判断新添加的categoryName 是否为空 if (string.IsNullOrEmpty(categoryName)) { return(RedirectToAction("List", new { msg = "分类名不能为空" })); } Category category = new Category(); category.Id = Guid.NewGuid(); category.CategoryNO = "Category_" + TimeManager.GetCurrentTimestamp(); category.CreatedTime = DateTime.Now.Date; category.IsDeleted = false; category.Name = categoryName; category.IsService = isService == 1 ? true : false; // 判断是否存在新添加的categoryName if (_categoryBLL.IsExist(categoryName)) { return(RedirectToAction("List", new { msg = "该分类已存在,请重新添加" })); } // 添加新Category if (_categoryBLL.Add(category)) { // 添加成功 return(RedirectToAction("List", new { msg = "添加成功" })); } else { return(RedirectToAction("List", new { msg = "添加失败" })); } }
public IActionResult Add(Category category) { var result = categoryBLL.Add(category); if (result.Succes) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public async Task <ActionResult> AddCategory(ViewModels.PM.Category.AddCategoryViewModel addCategoryViewModel) { if (ModelState.IsValid) { ImageErrorModel imageErrorModel = new ImageErrorModel(); string ImagePath = UploadImage(addCategoryViewModel.DefaultImage, ref imageErrorModel); if (imageErrorModel.isSuccess) { Category category = new Category() { Name = addCategoryViewModel.Name, DefaultImage = ImagePath, Description = addCategoryViewModel.Description }; await CategoryBLL.Add(category); return(RedirectToAction("Index")); } } return(View()); }
public ActionResult newCategory(CategoryInfo category) { if (!isAdmin()) { return(RedirectToAction("LogIn", "Main")); } if (ModelState.IsValid) { Customer c = (Customer)Session["loggedInUser"]; Category cat = new Category(); cat.ID = category.id; cat.name = category.name; bool OK = _categoryBLL.Add(cat, c.id); if (OK) { return(Json(new { success = true, message = cat.name + " ble lagt til.", redirect = "/Category/ListCategories?item_desc" })); } return(Json(new { success = false, message = "noe gikk galt, prøv igjen senere." })); } return(Json(new { success = false, message = "Feil i validering" })); }