public async Task <ActionResult> CreateSubCategory(AddSubCategoryViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
            try
            {
                var addSubCategoryRequest = new AddSubCategoryRequest {
                    CategoryId = request.CategoryId, Name = request.Name, Description = request.Description
                };
                var result = await _subCategoryService.Create(addSubCategoryRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
                }
                Alert($"Sub Category Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId }));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] SubCategoryViewModel value)
        {
            value = await service.Create(value);

            if (value == null)
            {
                return(BadRequest());
            }
            return(CreatedAtAction("Get", new { categoryId = value.CategoryId, id = value.Id }, value));
        }
Beispiel #3
0
        public async Task <ActionResult> Post(SubCategoryViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var result = await _service.Create(viewModel);

            if (!result)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Beispiel #4
0
        public IActionResult CreateSubCategory(SubCategoryForCreationDTO model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(Messages.ModelNullOrEmpty));
            }
            var subCategory = new SubCategory
            {
                SubCategoryName = model.SubCategoryName,
                CategoryId      = id
            };

            _subCategoryService.Create(subCategory);
            return(Ok());
        }
        public ActionResult CreateSubCategory(SubCategoryViewModel subcategory)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception(ModelState.ToString());
                }

                _subCategoryService.Create(subcategory);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Create(CreateSubCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedById = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var result = await _subCategoryService.Create(model);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, result.ErrorMessage);
            }
            var categoryList = await _categoryService.GetAll();

            ViewBag.CategoryDDL = categoryList.Result.Select(x => new SelectListItem
            {
                Selected = false,
                Text     = x.CategoryName,
                Value    = x.Id.ToString()
            }).ToList();
            return(View(model));
        }