Ejemplo n.º 1
0
        public long Create(Estoque estoque, IEnumerable <Estoque> estoques)
        {
            bool duplicada = false;

            foreach (var est in estoques)
            {
                if (est.AssignedProduct_Id == estoque.AssignedProduct.Id)
                {
                    duplicada = true;
                }
            }

            if (!duplicada)
            {
                if (estoque.Stock.GetType() == typeof(long))
                {
                    if (estoque.Price.GetType() == typeof(float))
                    {
                        if (estoque.AssignedProduct != null)
                        {
                            try
                            {
                                _estoqueRepository.InsertAndAttach(estoque);
                                return(_estoqueRepository.InsertAndGetId(estoque));
                            }
                            catch (Exception e)
                            {
                                throw new UserFriendlyException("Error 5", e.Message.ToString());
                            }
                        }
                        else
                        {
                            throw new UserFriendlyException("Error 4", "Please select a product");
                        }
                    }
                    else
                    {
                        throw new UserFriendlyException("Error 3", "Please insert a float value for the price");
                    }
                }
                else
                {
                    throw new UserFriendlyException("Error 2", "Please insert an integer number for stock");
                }
            }
            else
            {
                throw new UserFriendlyException("Error 1", "Product is already in stock");
            }
        }