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 }));
            }
        }
        public async Task <ServiceResponse <SubCategory> > Create(AddSubCategoryRequest request)
        {
            try
            {
                var category = await _subCategoryService.FindByIdInclusive(request.CategoryId, x => x.Include(p => p.SubCategories));

                if (!category.Success)
                {
                    return(new ServiceResponse <SubCategory>($"The Category does not exist"));
                }

                if (category.Data.SubCategories.Count > 0 && category.Data.SubCategories.Any(x => x.Name.ToLower().Equals(request.Name.ToLower())))
                {
                    return(new ServiceResponse <SubCategory>($"The Category already exist exist"));
                }

                var subCategory = new SubCategory
                {
                    Name        = request.Name,
                    Code        = GenerateCode(8),
                    Description = request.Description,
                    CategoryId  = category.Data.Id
                };
                var exist = await _baseRepository.GetByIdAndCode(subCategory.Id, subCategory.Code);

                if (exist != null)
                {
                    return(new ServiceResponse <SubCategory>($"A Sub Category With the Provided Code and or Id Already Exist"));
                }
                var exist2 = await _baseRepository.FindOneByConditions(x => x.Name.ToLower().Equals(subCategory.Name.ToLower()));

                if (exist2 != null)
                {
                    return(new ServiceResponse <SubCategory>($"A A Sub Category With the Provided Name Already Exist"));
                }

                //uomType.Data.UnitOfMeasures.Add(unitOfMeasure);

                await _baseRepository.Create(subCategory);

                return(new ServiceResponse <SubCategory>(subCategory));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <SubCategory>($"An Error Occured While Creating The Sub Category. {ex.Message}"));
            }
        }