Exemple #1
0
        public virtual async Task <ActionResult> AddAttribute(AddAttributeViewModel viewModel)
        {
            var categryId = viewModel.CategoryId;

            if (ModelState.IsValid)
            {
                var status = _attributeService.Add(viewModel);
                if (!status)
                {
                    ModelState.AddModelError("Name", "این ویژگی قبلا برای این گروه ثبت شده است");
                    return(View(viewModel));
                }
                if (viewModel.CascadeAddForChildren)
                {
                    var category = _categoryService.GetCategoryWithChildrenById(viewModel.CategoryId);
                    AddAttributeToChildrenCascade(viewModel, category);
                }
                await _unitOfWork.SaveChangesAsync();

                return(RedirectToAction(MVC.Admin.Category.ActionNames.AddAttribute, MVC.Admin.Category.Name,
                                        new { categoryId = categryId }));
            }
            PopulateCategoriesDropDownListForAttribute(categryId);
            return(View(viewModel));
        }
        public IActionResult Post([FromBody] VM viewModel)
        {
            var data = Mapper.Map <VM, T>(viewModel);

            _attributeService.Add(data);

            // Exception handling goes here - leading to 500 (if Exception) or BadRequest (if ApplicationException)

            return(Ok());
        }