コード例 #1
0
        public async Task <IActionResult> GetProductionSessions()
        {
            var sessionsFromRepo = await _repository.GetAll <ProductionSession>();

            var sessionListToReturn = _mapper.Map <IEnumerable <ProdSessionForDetailDto> >(sessionsFromRepo);

            return(Ok(sessionListToReturn));
        }
コード例 #2
0
        public IActionResult GetProduct(string storeName, Guid userId, List <string> restrictions)
        {
            Store store = _storeRepository.GetStoreByName(storeName);

            var actionResulValidation = Validate(storeName, userId, store);

            if (actionResulValidation != null)
            {
                return(actionResulValidation);
            }

            if (restrictions == null || restrictions[0].Equals("{restrictions}"))
            {
                restrictions = new List <string>();
            }

            var restrictionTratado = string.Empty;

            if (restrictions.Count > 0)
            {
                restrictionTratado = restrictions[0].Replace(",", "|");
            }

            var restrictionList = restrictionTratado.Split("|").ToList();

            var user = new User()
            {
                UserId = userId, Restrictions = restrictionList
            };

            #region Request //GET api/production/areas request - Request sem parametro

            var areas = _productionRepository.GetAll();

            #endregion

            #region Request //GET api/products request (on StoreCatalog API)

            var products = _productRepository.GetAll();

            #endregion

            #region Request //GET api/products/byrestrictions request

            List <Ingredients.Contract.Response.IngredientsToUpsert> productsFilter = _apiService.GetProductsByRestrictions(store.StoreId, restrictionTratado).Result;

            if (productsFilter == null)
            {
                return(NoContent());
            }

            #endregion

            #region Filtro de produtos por restrictions

            IEnumerable <Product> retorno = new List <Product>();

            try
            {
                var allowedAreas = areas.Where(area => user.Restrictions.All(restriction => area.Restrictions.Select(rest => rest.Restriction).Contains(restriction)));

                var allowedProducts = productsFilter.Where(product => product
                                                           .Ingredients.All(ingredient =>
                                                                            allowedAreas.Any(area => !area.Restrictions.Select(rest => rest.Restriction).Contains(ingredient))));

                if (allowedProducts.Count() < 2)
                {
                    _lessOfferService.SendMessagesAsync(JsonConvert.SerializeObject(user));
                }

                retorno = products.Where(x => allowedProducts.Any(y => y.ProductId == x.ProductId));
            }
            catch (Exception ex)
            {
                _logService.SendMessagesAsync($"Error when try to filter products by restrictions. Message: {ex.Message}");
                return(StatusCode(500));
            }

            #endregion

            if (retorno.Count() > 0)
            {
                return(Ok(retorno));
            }
            else
            {
                return(NoContent());
            }
        }