示例#1
0
        public async Task AddCategory(CategoriesAddViewModel category)
        {
            var addcategory = _mapper.Map <Category>(category);

            _context.Categories.Add(addcategory);
            await _context.SaveChangesAsync();
        }
示例#2
0
        public ActionResult Add()
        {
            var model = new CategoriesAddViewModel();

            SetupAddViewModel(model);

            return View(model);
        }
示例#3
0
        public ActionResult Add()
        {
            var model = new CategoriesAddViewModel();

            SetupAddViewModel(model);

            return(View(model));
        }
示例#4
0
        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
            });
        }
示例#5
0
        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);
        }
示例#6
0
        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));
        }
示例#7
0
        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());
        }
示例#8
0
        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());
        }
示例#9
0
        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
                       });
        }
示例#10
0
 public ECategoryProduct Add_Category(CategoriesAddViewModel item)
 {
     throw new NotImplementedException();
 }