public void CreateCategory(CategoryDomainModel category)
        {
            var createCategory = mapper.Map <Category>(category);

            categoryRepository.CreateCategory(createCategory);
            categoryRepository.Save();
        }
Example #2
0
        public async Task <string> AddUpdateCategory(CategoryVM categoryVM)
        {
            CategoryDomainModel categoryDM = new CategoryDomainModel();

            AutoMapper.Mapper.Map(categoryVM, categoryDM);
            return(await categoryBusiness.AddUpdateCategory(categoryDM));
        }
        public async Task <string> AddUpdateCategory(CategoryDomainModel category)
        {
            string status = "";

            if (category.cat_id > 0)
            {
                tblCategory categoryToUpdate = await categoryRepository.SingleOrDefault(c => c.cat_id == category.cat_id);

                if (categoryToUpdate != null)
                {
                    categoryToUpdate.cat_id     = category.cat_id;
                    categoryToUpdate.name       = category.name;
                    categoryToUpdate.mainCat_id = category.mainCat_id;

                    await categoryRepository.Update(categoryToUpdate);

                    status = "updated";
                }
            }
            else
            {
                tblCategory categoryToAdd = new tblCategory();
                categoryToAdd.cat_id     = category.cat_id;
                categoryToAdd.name       = category.name;
                categoryToAdd.mainCat_id = category.mainCat_id;

                await categoryRepository.Insert(categoryToAdd);

                status = "added";
            }
            return(status);
        }
Example #4
0
        public async Task <CategoryToReturnVM> GetCategoryById(int id)
        {
            CategoryToReturnVM  categoryToReturnVM  = new CategoryToReturnVM();
            CategoryDomainModel categoryDomainModel = await categoryBusiness.GetCategoryById(id);

            AutoMapper.Mapper.Map(categoryDomainModel, categoryToReturnVM);
            return(categoryToReturnVM);
        }
Example #5
0
        public PartialViewResult Menu(string category = null)
        {
            ViewBag.SelectedCategory = category;
            CategoryDomainModel    cat  = new CategoryDomainModel();
            IEnumerable <Category> cats = cat.GetAll();

            return(PartialView(cats));
        }
        public async Task <CategoryDomainModel> GetCategoryById(int id)
        {
            CategoryDomainModel category = new CategoryDomainModel();
            var model = await categoryRepository.SingleOrDefault(c => c.cat_id == id);

            if (model != null)
            {
                category            = new CategoryDomainModel();
                category.cat_id     = model.cat_id;
                category.name       = model.name;
                category.mainCat_id = model.mainCat_id;
            }
            return(category);
        }
Example #7
0
        public bool Update(ProductDomainModel model)
        {
            ProductDomainModel oldProduct = Date.Products.FirstOrDefault(x => x.Id == model.Id);

            if (oldProduct != null)
            {
                CategoryDomainModel category = Data.Date.Categories.FirstOrDefault(x => x.Id == model.CategoryId);
                if (category == null)
                {
                    return(false);
                }
                oldProduct.Category = category;
                oldProduct.Name     = model.Name;
                oldProduct.Price    = model.Price;
                return(true);
            }
            return(false);
        }
Example #8
0
        /// <summary>
        ///     Gets all ancestor's categories related to the current good.
        /// </summary>
        /// <param name="categoryDomainModels">
        ///     Collection of instances of <see cref="CategoryDomainModel"/>
        /// </param>
        /// <param name="category">
        ///     Category of good.
        /// </param>
        /// <returns>
        ///     Main category of good.
        /// </returns>
        private CategoryDomainModel GetAncestorsCategories(
            IList <CategoryDomainModel> categoryDomainModels,
            XElement category)
        {
            if (category?.Element(this._xns + "Ancestors") != null)
            {
                var parentCategory = category.Element(this._xns + "Ancestors")
                                     .Element(this._xns + "BrowseNode");

                var parentCategoryDomainModel = this.GetAncestorsCategories(categoryDomainModels, parentCategory);

                var categoryDomainModel = new CategoryDomainModel
                {
                    IdAtStore       = category.Element(this._xns + "BrowseNodeId").Value,
                    Name            = category.Element(this._xns + "Name").Value,
                    ParentIdAtStore = parentCategoryDomainModel.IdAtStore
                };

                categoryDomainModels.Add(categoryDomainModel);

                return(categoryDomainModel);
            }
            else
            {
                var categoryDomainModel = new CategoryDomainModel
                {
                    IdAtStore = category.Element(this._xns + "BrowseNodeId").Value,
                    Name      = category.Element(this._xns + "Name") == null
                        ? "Other category"
                        : category.Element(this._xns + "Name").Value,
                    ParentIdAtStore = null
                };

                categoryDomainModels.Add(categoryDomainModel);

                return(categoryDomainModel);
            }
        }