Esempio n. 1
0
        public async Task <IHttpActionResult> GetSelectedCategory(GetSelectedCategoryModel model)
        {
            try
            {
                var resultOfSearch = GetLotByCategory(model);
                if (resultOfSearch.Count == 0)
                {
                    return(await Task.FromResult(BadRequest("There are no products in this category!")));
                }

                return(await Task.FromResult(Ok(resultOfSearch)));
            }
            catch (Exception exception)
            {
                return(NotFound());
            }
        }
Esempio n. 2
0
        private List <CategoryApiModel> GetLotByCategory(GetSelectedCategoryModel model)
        {
            List <Categories> categoriesList;

            using (BaseModelRepository <Categories> categoryRepository =
                       new BaseModelRepository <Categories>(new AuctionDb()))
            {
                categoriesList = categoryRepository.GetAll().Where(filter => filter.CategoryName == model.CategoryName).ToList();


                using (
                    BaseModelRepository <LotDetailsModel> lotDetailsRepository =
                        new BaseModelRepository <LotDetailsModel>(new AuctionDb()))
                {
                    var lots   = lotDetailsRepository.GetAll().ToList();
                    var models = new List <CategoryApiModel>();

                    foreach (var lotDetailsModel in lots)
                    {
                        foreach (var category in categoriesList)
                        {
                            //var lotDetailsModel = lot;
                            //var categoryModel = category;
                            //models.AddRange(from subCategory in category.SubCategoryId
                            //	where subCategory.SubCategoryName == model.SubCategoryName
                            //	select lot.LotId.Select(lotModel => lotModel).Where(subLotFilter => subLotFilter.Id == lot.Id).ToList()
                            //	into subQuery
                            //	select subQuery.ToList().Select(subLot => new LotApiModel()
                            //	{
                            //		Name = subLot.Name
                            //	}).ToList()
                            //	into lotsApi
                            //	select new LotDetailsApiModel()
                            //	{
                            //		Address = lotDetailsModel.Adress,
                            //		Description = lotDetailsModel.Description,
                            //		Price = lotDetailsModel.Price,
                            //		Lots = lotsApi
                            //	}
                            //	into lotDeatailsApi
                            //	select new CategoryApiModel()
                            //	{
                            //		CategoryName = categoryModel.CategoryName,
                            //		LotDetailsApiModelsApiModels = lotDeatailsApi
                            //	});

                            if (category.Id == lotDetailsModel.CategoryId.Id)
                            {
                                models.Add(new CategoryApiModel()
                                {
                                    CategoryName = category.CategoryName,
                                    LotDetailsApiModelsApiModels = new LotDetailsApiModel()
                                    {
                                        Id          = lotDetailsModel.Id,
                                        Address     = lotDetailsModel.Adress,
                                        Description = lotDetailsModel.Description,
                                        Price       = lotDetailsModel.Price,
                                        //Lots = new List<LotApiModel>()
                                        //{
                                        //	new LotApiModel()
                                        //	{
                                        //		Name = lot.LotId.FirstOrDefault(elem => elem.LotDetailsId == lot).Name
                                        //	}
                                        //}
                                    }
                                });
                            }
                        }
                    }

                    return(models);
                }
            }
        }