예제 #1
0
        public AddCompoundResponse AddCompoundSimpleProduct(AddCompoundRequest request)
        {
            var compound = new Compound();

            request.Minutas.ForEach(delegate(MinutaRequest minutaRequest)
            {
                var product = UnitOfWork.ProductRepository.Find(minutaRequest.IdProduct);
                if (product != null)
                {
                    compound.AddMinuta(product, minutaRequest.Cantidad);
                }
            });
            if (compound.Ingredients.Count == request.Minutas.Count)
            {
                compound.Name         = request.Name;
                compound.PriceProduct = request.Price;
                compound.Type         = request.Type;
                UnitOfWork.ProductRepository.Add(compound);
                UnitOfWork.Commit();
                return(new AddCompoundResponse()
                {
                    Message = "Producto Compuesto Creado Con exito."
                });
            }
            else
            {
                return(new AddCompoundResponse()
                {
                    Message = "Los productos y las cantidades no son validas."
                });
            }
        }