Beispiel #1
0
        public async Task <ActionResult <IEnumerable <PlaceProductWithPlace> > > ListPlaceProduct()
        {
            try
            {
                var pp = await placeProviderRepository.GetPlaceProvider(User.GetPlaceProvider());

                if (pp == null)
                {
                    throw new Exception("Place provider not found");
                }
                var ret = await placeRepository.ListPlaceProductByPlaceProvider(pp);

                var places = await placeRepository.ListAll();

                var places2 = IPlaceProviderRepository.ExtendByAllProducts(ret, pp, places.Where(pp => pp.PlaceProviderId == User.GetPlaceProvider()).Select(p => p.Id).ToArray());

                return(Ok(places2.Select(ppr => ppr.ToExtendedModel(placeProviderRepository).Result)));
            }
            catch (ArgumentException exc)
            {
                logger.LogError(exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }
        public async Task <ActionResult <IEnumerable <PlaceProduct> > > ListPlaceProductByPlaceProvider(
            [FromQuery] string placeProviderId
            )
        {
            try
            {
                var pp = await placeProviderRepository.GetPlaceProvider(placeProviderId);

                if (pp == null)
                {
                    throw new Exception("Place provider not found");
                }
                var ret = await placeRepository.ListPlaceProductByPlaceProvider(pp);

                var places = await placeRepository.ListAll();

                return(Ok(IPlaceProviderRepository.ExtendByAllProducts(ret, pp, places.Where(pp => pp.PlaceProviderId == placeProviderId).Select(p => p.Id).ToArray())));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);

                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }
        public async Task <ActionResult <IEnumerable <PlaceProductWithPlace> > > ListPlaceProductByPlace(
            [FromQuery] string placeId
            )
        {
            try
            {
                var place = await placeRepository.GetPlace(placeId);

                if (place == null)
                {
                    throw new Exception("Place not found");
                }
                var pp = await placeProviderRepository.GetPlaceProvider(place.PlaceProviderId);

                if (pp == null)
                {
                    throw new Exception("Place provider not found");
                }
                var ret = await placeRepository.ListPlaceProductByPlace(placeId);

                var places2 = IPlaceProviderRepository.ExtendByAllProducts(ret, pp, new string[] { placeId });
                return(Ok(places2.Select(ppr => ppr.ToExtendedModel(placeProviderRepository).Result)));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);

                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }
Beispiel #4
0
        /// <summary>
        /// ListPlaceProductByCategory
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public async Task <IEnumerable <PlaceProduct> > ListPlaceProductByCategory(string category)
        {
            var ret = new List <PlaceProduct>();

            foreach (var ppId in await ListPPIdsByCategory(category))
            {
                var pp = await GetPlaceProvider(ppId);

                if (pp.Products.Any(p => p.Category == category))
                {
                    ret.AddRange(await placeRepository.ListPlaceProductByPlaceProvider(pp));
                }
                var places = await placeRepository.ListAll();

                var placesIds = places.Where(ppobj => ppobj.PlaceProviderId == pp.PlaceProviderId).Select(p => p.Id).ToArray();

                ret = IPlaceProviderRepository.ExtendByAllProducts(ret, pp, placesIds);
            }

            return(ret);
        }