public async Task AddCategory(CategoriesAddViewModel category) { var addcategory = _mapper.Map <Category>(category); _context.Categories.Add(addcategory); await _context.SaveChangesAsync(); }
public ActionResult Add() { var model = new CategoriesAddViewModel(); SetupAddViewModel(model); return View(model); }
public ActionResult Add() { var model = new CategoriesAddViewModel(); SetupAddViewModel(model); return(View(model)); }
private void SetupAddViewModel(CategoriesAddViewModel model) { model.ParentCategoryIDListItems = new List <SelectListItem> { new SelectListItem() }; model.ParentCategoryIDListItems.AddRange( from c in _session.Query <Category>() select new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); }
public ActionResult Add([Bind(Prefix = "AddForm")] CategoriesAddForm form) { var model = new CategoriesAddViewModel(); if (ModelState.IsValid) { var category = new Category { Name = form.Name, Description = form.Description ?? string.Empty, ParentCategory = form.ParentCategoryID == null ? null : _session.Load<Category>(form.ParentCategoryID) }; _session.Save(category); TempData["SuccessMessage"] = "Category has been created"; return RedirectToAction("Index"); } SetupAddViewModel(model); return View(model); }
public ActionResult Add([Bind(Prefix = "AddForm")] CategoriesAddForm form) { var model = new CategoriesAddViewModel(); if (ModelState.IsValid) { var category = new Category { Name = form.Name, Description = form.Description ?? string.Empty, ParentCategory = form.ParentCategoryID == null ? null : _session.Load <Category>(form.ParentCategoryID) }; _session.Save(category); TempData["SuccessMessage"] = "Category has been created"; return(RedirectToAction("Index")); } SetupAddViewModel(model); return(View(model)); }
public async Task <IActionResult> AddCategory([FromBody] CategoriesAddViewModel category) { if (ModelState.IsValid) { if (await _categoryService.CategoryExists(category.Name)) { return(BadRequest("Category already exists")); } if (!(await _categoryService.ParentCategoryExists((int)category.ParentCategoryId))) { return(BadRequest("Parent Category is not a main Category")); } await _categoryService.AddCategory(category); return(StatusCode(201, "Successfully added category")); } return(BadRequest()); }
public async Task <IActionResult> AddSubCategory(string name, [FromBody] CategoriesAddViewModel category) { if (ModelState.IsValid) { var mainCategory = await _categoryService.GetCategory(name); if (mainCategory.ParentCategoryId != 1) { return(BadRequest("Not a main Category")); } if (await _categoryService.CategoryExists(category.Name)) { return(BadRequest("Category already exists")); } category.ParentCategoryId = mainCategory.Id; await _categoryService.AddCategory(category); return(StatusCode(201, "Successfully added category")); } return(BadRequest()); }
private void SetupAddViewModel(CategoriesAddViewModel model) { model.ParentCategoryIDListItems = new List<SelectListItem> { new SelectListItem() }; model.ParentCategoryIDListItems.AddRange( from c in _session.Query<Category>() select new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); }
public ECategoryProduct Add_Category(CategoriesAddViewModel item) { throw new NotImplementedException(); }