public ActionResult <GenderReadDto> GetGenderById(int id)
        {
            var genderItem = _repository.GetGenderById(id);

            if (genderItem != null)
            {
                return(Ok(_mapper.Map <GenderReadDto>(genderItem)));
            }
            return(NotFound());
        }
Example #2
0
        public ActionResult <IEnumerable <ProductReadDto> > Create()
        {
            FiltersReadDto filter = new FiltersReadDto();

            //ReadPrice
            var priceFilter = new FilterForPriceReadDto();

            priceFilter.MaxPriceFrom = _productRepo.GetMinPriceOfProducts(products);
            priceFilter.MaxPriceTo   = _productRepo.GetMaxPriceOfProducts(products);
            if (priceFilter.MaxPriceFrom != null || priceFilter.MaxPriceTo != null)
            {
                filter.PriceFilter = priceFilter;
            }

            //ReadCategory
            var categories = new List <Category>();

            if (products != null)
            {
                foreach (Product product in products)
                {
                    if (!categories.Contains(product.Category))
                    {
                        categories.Add(product.Category);
                    }
                }
            }
            var categoriesFilter = new FilterForCategoriesReadDto();
            var categoryList     = new List <FilterForCategoryReadDto>();

            for (int i = 0; i < categories.Count; i++)
            {
                var length = _productRepo.GetLegthOfProductList(categories[i], products);
                if (length > 0)
                {
                    var filterCategory = new FilterForCategoryReadDto();
                    filterCategory.Length = length;
                    filterCategory.Id     = categories[i].Id;
                    filterCategory.Name   = categories[i].Name;
                    categoryList.Add(filterCategory);
                }
            }
            categoriesFilter.listOfCategoryFilter = categoryList;
            filter.CategoriesFilter = categoriesFilter;

            //ReadGender
            var genderFilterList = new GendersFilter();
            var genderList       = new List <FilterForGenderReadDto>();
            var listOfGenderId   = _genderOfProductRepo.GetAllIdOfGenders(products);

            if (listOfGenderId != null)
            {
                foreach (int Id in listOfGenderId)
                {
                    var genderFilter = new FilterForGenderReadDto();
                    var gender       = _genderRepo.GetGenderById(Id);
                    var length       = _genderOfProductRepo.LengthOfGender(gender, products);
                    if (length > 0)
                    {
                        genderFilter.Id     = gender.Id;
                        genderFilter.Name   = gender.Name;
                        genderFilter.Length = length;
                        genderList.Add(genderFilter);
                    }
                }
                genderFilterList.GenderList = genderList;
            }
            filter.GenderFilter = genderFilterList;

            //ReadSize
            var sizeFilter  = new FilterSizes();
            var sizeFilters = new List <FilterForSizeReadDto>();
            var sizesList   = _sizeOfProductRepo.GetAllIdOfSize(products);

            if (sizesList != null)
            {
                foreach (var Id in sizesList)
                {
                    var sizes  = new FilterForSizeReadDto();
                    var size   = _sizeRepo.GetSizeById(Id);
                    var length = _sizeOfProductRepo.LengthOfSize(size, products);
                    if (length > 0)
                    {
                        sizes.Id     = size.Id;
                        sizes.Name   = size.Name;
                        sizes.Length = length;
                        sizeFilters.Add(sizes);
                    }
                }
                sizeFilter.sizesFilterList = sizeFilters;
                filter.SizeFilter          = sizeFilter;
            }
            return(Ok(filter));
        }