Пример #1
0
        public async Task <IActionResult> SubCategory(CategorySubViewModel categorySubViewModel, string subCategory)
        {
            if (ModelState.IsValid)
            {
                CategorySubViewModel createSubCategory = new CategorySubViewModel
                {
                    MainCat = categorySubViewModel.Id,
                    Name    = subCategory,
                    Status  = categorySubViewModel.Status,
                };

                Category createCategory = _iMapper.Map <Category>(createSubCategory);
                bool     isAdd          = await _iCategoryManager.Create(createCategory);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Failed to Save Category";
                }
            }

            return(View(categorySubViewModel));
        }
Пример #2
0
        public static bool EditCategorySub(CategorySubViewModel model)
        {
            if (model.Id > 0)
            {
                try
                {
                    IQueryable <CategorySub> categorysub = identityASPdb.CategorySub.Where(x => x.Id == model.Id);
                    if (categorysub != null)
                    {
                        foreach (var item in categorysub)
                        {
                            item.Id          = model.Id;
                            item.Description = model.Description;
                            identityASPdb.Entry(item).State = EntityState.Modified;
                        }
                        identityASPdb.SaveChanges();
                        result = true;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(result);
        }
        public ActionResult SaveCategorySub(CategorySubViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    result   = CategorySubBusiness.AddCategorySub(model, out categorysubId);
                    model.Id = categorysubId;
                    if (result)
                    {
                        return(Json(new { data = model, success = result + "Add", JsonRequestBehavior.AllowGet }));
                    }
                }
                else if (model.Id != 0)
                {
                    result = CategorySubBusiness.EditCategorySub(model);
                    if (result)
                    {
                        return(Json(new { data = model, success = result + "Edit", JsonRequestBehavior.AllowGet }));
                    }
                }
            }

            return(Json(new { success = result }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetCategoriesSub(int categoryId)
        {
            var model = new CategorySubViewModel();

            model.CategorySubList = CategorySubBusiness.GetCategoriesSubByCategoryId(categoryId);

            return(Json(new { data = model.CategorySubList, success = "true", JsonRequestBehavior.AllowGet }));
        }
Пример #5
0
        public static CategorySubViewModel GetCategorySubByCategorySubIdAndCategoryId(int categorysubId, int categoryId)
        {
            CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.isDelete != true && x.Id == categorysubId && x.CategoryId == categoryId).FirstOrDefault();

            var model = new CategorySubViewModel();

            model.Id          = categorySub.Id;
            model.Description = categorySub.Description;
            model.CategoryId  = categorySub.CategoryId;
            return(model);
        }
Пример #6
0
        public static List <CategorySubViewModel> GetCategoriesSubByCategoryId(int categoryId)
        {
            List <CategorySub> categoriesSub = identityASPdb.CategorySub.Where(x => x.isDelete != true && x.CategoryId == categoryId).ToList();
            var categoriesSubList            = new List <CategorySubViewModel>();

            foreach (var item in categoriesSub)
            {
                var categorySub = new CategorySubViewModel();
                categorySub.Id          = item.Id;
                categorySub.Description = item.Description;
                categoriesSubList.Add(categorySub);
            }

            return(categoriesSubList);
        }
Пример #7
0
        public async Task <ActionResult <CategorySubViewModel> > SubCategory(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CategorySubViewModel subCategory = _iMapper.Map <CategorySubViewModel>
                                                   (await _iCategoryManager.GetById(id));

            if (subCategory == null)
            {
                return(NotFound());
            }

            return(View(subCategory));
        }
Пример #8
0
        public static bool AddCategorySub(CategorySubViewModel model, out int categorysubId)
        {
            var categorysub = new CategorySub();

            if (model.Id == 0)
            {
                try
                {
                    categorysub.CategoryId  = model.CategoryId;
                    categorysub.Id          = model.Id;
                    categorysub.Description = model.Description;
                    identityASPdb.CategorySub.Add(categorysub);
                    identityASPdb.SaveChanges();
                    result = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            categorysubId = categorysub.Id;
            return(result);
        }