Exemple #1
0
        public async Task <IHttpActionResult> GetCategories()
        {
            List <CategoryApiModel> categoryModels = new List <CategoryApiModel>();

            try
            {
                using (BaseModelRepository <Categories> repository =
                           new BaseModelRepository <Categories>(new AuctionDb()))
                {
                    var categoriesModels = repository.GetAll().ToList();

                    categoriesModels.ForEach(elem => categoryModels.Add(new CategoryApiModel()
                    {
                        CategoryName      = elem.CategoryName,
                        SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryApiModel()
                        {
                            SubCategoryName = sub.SubCategoryName
                        }).ToList()
                    }));
                }
            }
            catch (Exception exception)
            {
                return(NotFound());
            }

            return(await Task.FromResult(Ok(categoryModels)));
        }
        public async Task<IHttpActionResult> GetCategories()
        {
            List<CategoryApiModel> categoryModels = new List<CategoryApiModel>();
            
            try
            {
				using (BaseModelRepository<Categories> repository = 
					new BaseModelRepository<Categories>(new AuctionDb()))
                {
                    var categoriesModels = repository.GetAll().ToList();

					categoriesModels.ForEach(elem => categoryModels.Add(new CategoryApiModel()
                    {
                        CategoryName = elem.CategoryName,
						SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryApiModel()
								{
									SubCategoryName = sub.SubCategoryName
								}).ToList()
					}));
				}
            }
            catch (Exception exception)
            {
				return NotFound();
            }

	        return await Task.FromResult(Ok(categoryModels));
        }
Exemple #3
0
        public async Task <IHttpActionResult> GetCategories()
        {
            List <ApiModels.CategoryModel> categoryModels = new List <CategoryModel>();

            try
            {
                using (AuctionDb context = new AuctionDb())
                {
                    BaseModelRepository <DomainModels.Categories.CategoryModel> repository =
                        new BaseModelRepository <DomainModels.Categories.CategoryModel>(context);
                    var categoriesModels = repository.GetAll().ToList();

                    //foreach (var category in categoriesModels)
                    //{
                    //	categoryModels.Add(new CategoryModel()
                    //	{
                    //		Id = category.Id,
                    //		SubCategoryModels =
                    //	});
                    //}


                    categoriesModels.ForEach(elem => categoryModels.Add(new ApiModels.CategoryModel()
                    {
                        Id                = elem.Id,
                        CategoryName      = elem.CategoryName,
                        SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryModel()
                        {
                            Id = sub.Id,
                            SubCategoryName = sub.SubCategoryName
                        }).ToList()
                                            //SubCategoryModels = new List<SubCategoryModel>()
                                            //{
                                            //	new SubCategoryModel()
                                            //	{
                                            //		Id = elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.Id,

                                            //		SubCategoryName =
                                            //			elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.SubCategoryName
                                            //	}
                                            //}
                    }));
                }
            }
            catch (Exception exception)
            {
                var ex = exception;
                return(NotFound());
            }



            return(Ok(categoryModels));
        }
        public async Task<IHttpActionResult> GetCategories()
        {
            List<ApiModels.CategoryModel> categoryModels = new List<CategoryModel>();
            
            try
            {
                using (AuctionDb context = new AuctionDb())
                {
                    BaseModelRepository<DomainModels.Categories.CategoryModel> repository =
                        new BaseModelRepository<DomainModels.Categories.CategoryModel>(context);
                    var categoriesModels = repository.GetAll().ToList();

					//foreach (var category in categoriesModels)
					//{
					//	categoryModels.Add(new CategoryModel()
					//	{
					//		Id = category.Id,
					//		SubCategoryModels = 
					//	});
					//}


					categoriesModels.ForEach(elem => categoryModels.Add(new ApiModels.CategoryModel()
                    {
                        Id = elem.Id,
                        CategoryName = elem.CategoryName,
						SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryModel()
								{
									Id = sub.Id,
									SubCategoryName = sub.SubCategoryName
								}).ToList()
						//SubCategoryModels = new List<SubCategoryModel>()
						//{		
						//	new SubCategoryModel()
						//	{
						//		Id = elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.Id,

						//		SubCategoryName =
						//			elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.SubCategoryName
						//	}
						//}
					}));
				}
            }
            catch (Exception exception)
            {
                var ex = exception;
                return NotFound();
            }

        

            return Ok(categoryModels);
        }
Exemple #5
0
 public IHttpActionResult GetStatus()
 {
     try
     {
         using (BaseModelRepository <StatusModel> statusRepository =
                    new BaseModelRepository <StatusModel>(new AuctionDb()))
         {
             var result = statusRepository.GetAll().Select(status => status.Status).ToList();
             return(Ok(result));
         }
     }
     catch (Exception exception)
     {
         return(NotFound());
     }
 }
		public IHttpActionResult GetStatus()
		{
			try
			{
				using (BaseModelRepository<StatusModel> statusRepository =
					new BaseModelRepository<StatusModel>(new AuctionDb()))
				{
					var result = statusRepository.GetAll().Select(status => status.Status).ToList();
					return Ok(result);
				}
			}
			catch (Exception exception)
			{
				return NotFound();
			}
		}
Exemple #7
0
        public IHttpActionResult Delete(Guid lotDetailsId)
        {
            var deleted = false;

            try
            {
                using (BaseModelRepository <LotModel> lotRepository =
                           new BaseModelRepository <LotModel>(new AuctionDb()))
                {
                    var lots =
                        lotRepository.GetAll()
                        .Where(lot => lot.LotDetailsId.ToString() == lotDetailsId.ToString()).ToList();

                    if (lotRepository.Delete(lots))
                    {
                        deleted = true;
                    }
                }

                if (deleted)
                {
                    using (BaseModelRepository <LotDetailsModel> lotDetailsRepository = new BaseModelRepository <LotDetailsModel>(new AuctionDb()))
                    {
                        var lotDetToDelete = lotDetailsRepository.GetAll().Where(lot => lot.Id == lotDetailsId);

                        if (lotDetailsRepository.Delete(lotDetToDelete))
                        {
                            deleted = true;
                        }
                    }

                    return(Ok());
                }
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }

            return(BadRequest());
        }
		public IHttpActionResult Delete(Guid lotDetailsId)
		{
			var deleted = false;
			try
			{
				using (BaseModelRepository<LotModel> lotRepository =
					new BaseModelRepository<LotModel>(new AuctionDb()))
				{
					var lots =
						lotRepository.GetAll()
							.Where(lot => lot.LotDetailsId.ToString() == lotDetailsId.ToString()).ToList();

					if (lotRepository.Delete(lots))
					{
						deleted = true;
					}
				}

				if (deleted)
				{
					using (BaseModelRepository<LotDetailsModel> lotDetailsRepository = new BaseModelRepository<LotDetailsModel>(new AuctionDb()))
					{
						var lotDetToDelete = lotDetailsRepository.GetAll().Where(lot => lot.Id == lotDetailsId);

						if (lotDetailsRepository.Delete(lotDetToDelete))
						{
							deleted = true;
						}
					}

					return Ok();
				}
			}
			catch (Exception exception)
			{
				return BadRequest(exception.Message);
			}

			return BadRequest();
		}
Exemple #9
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);
                }
            }
        }
Exemple #10
0
        public IHttpActionResult AddNewLot(AddLotApiModel lotModel)
        {
            CategoryModel categoriesList;
            StatusModel   statusModel;

            using (BaseModelRepository <CategoryModel> categoryRepository =
                       new BaseModelRepository <CategoryModel>(new AuctionDb()))
            {
                categoriesList = categoryRepository.GetAll()
                                 .Select(elem => elem).FirstOrDefault(
                    sub => sub.CategoryName == lotModel.Category
                    &&
                    sub.SubCategoryId.Any(elem => elem.SubCategoryName == lotModel.SubCategory));
            }

            using (BaseModelRepository <StatusModel> statusRepository =
                       new BaseModelRepository <StatusModel>(new AuctionDb()))
            {
                statusModel =
                    statusRepository.GetAll().Select(status => status).FirstOrDefault(elem => elem.Status == lotModel.Status);

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

            try
            {
                using (BaseModelRepository <LotModel> lotModelRepository =
                           new BaseModelRepository <LotModel>(new AuctionDb()))
                {
                    var claimsIdentity = User.Identity as ClaimsIdentity;
                    if (claimsIdentity == null)
                    {
                        return(Unauthorized());
                    }

                    var claims = claimsIdentity.Claims.Select(claim => claim).FirstOrDefault(subj => subj.Type == "userIdString");
                    if (claims == null)
                    {
                        return(Unauthorized());
                    }

                    var user = lotModelRepository.GetAll()
                               .Select(elem => elem.ApplicationUsersId.FirstOrDefault(filter => filter.Id == claims.Value)).ToList()
                               .Select(element => element).Where(applicationUser => applicationUser != null).ToList();


                    LotModel model = new LotModel()
                    {
                        Id = Guid.NewGuid(),
                        ApplicationUsersId = user,
                        LotDetailsId       = new LotDetailsModel(),
                        Name     = lotModel.Name,
                        StatusId = statusModel.Id
                    };

                    lotModelRepository.Add(model);
                }
                return(Ok());
            }
            catch (Exception exception)
            {
                return(Unauthorized());
            }

            return(BadRequest());
        }
		public IHttpActionResult AddNewLot(AddLotApiModel lotModel)
		{
			CategoryModel categoriesList;
			StatusModel statusModel;

			using (BaseModelRepository<CategoryModel> categoryRepository = 
				new BaseModelRepository<CategoryModel>(new AuctionDb()))
			{
				categoriesList = categoryRepository.GetAll()
					.Select(elem => elem).FirstOrDefault(
						sub => sub.CategoryName == lotModel.Category
						       &&
						       sub.SubCategoryId.Any(elem => elem.SubCategoryName == lotModel.SubCategory));
			}

			using (BaseModelRepository<StatusModel> statusRepository = 
				new BaseModelRepository<StatusModel>(new AuctionDb()))
			{
				statusModel =
					statusRepository.GetAll().Select(status => status).FirstOrDefault(elem => elem.Status == lotModel.Status);

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

			try
			{
				using (BaseModelRepository<LotModel> lotModelRepository = 
					new BaseModelRepository<LotModel>(new AuctionDb()))
				{
					var claimsIdentity = User.Identity as ClaimsIdentity;
					if (claimsIdentity == null) return Unauthorized();

					var claims = claimsIdentity.Claims.Select(claim => claim).FirstOrDefault(subj => subj.Type == "userIdString");
					if (claims == null) return Unauthorized();

					var user = lotModelRepository.GetAll()
						.Select(elem => elem.ApplicationUsersId.FirstOrDefault(filter => filter.Id == claims.Value)).ToList()
						.Select(element => element).Where(applicationUser => applicationUser != null).ToList();


					LotModel model = new LotModel()
					{
						Id = Guid.NewGuid(),
						ApplicationUsersId = user,
						LotDetailsId = new LotDetailsModel(),
						Name = lotModel.Name,
						StatusId = statusModel.Id
					};

					lotModelRepository.Add(model);
				}
				return Ok();
			}
			catch (Exception exception)
			{
				return Unauthorized();
			}

			return BadRequest();
		}
		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;
				}
			}
	    }