private List <SelectedProduct> FillSelectedProducts(IEnumerable <Model.SelectedProduct> request,
                                                            string transactionId, out decimal totalPrice)
        {
            var result = new List <SelectedProduct>();

            totalPrice = 0;

            foreach (var sp in request)
            {
                var product = _dacProduct.Single(sp.Product.Id);

                if (product == null)
                {
                    continue;
                }

                var subTotal        = sp.Quantity * product.Price;
                var selectedProduct = new SelectedProduct
                {
                    Id            = GenerateId(),
                    ProductId     = product.Id,
                    ProductName   = product.Name,
                    ProductPrice  = product.Price,
                    TransactionId = transactionId,
                    Notes         = sp.Notes,
                    Quantity      = sp.Quantity,
                    TotalPrice    = subTotal
                };

                result.Add(selectedProduct);
                totalPrice += subTotal;
            }

            return(result);
        }
Esempio n. 2
0
        public ActionResult <CollectionResponse <Product> > Get(string id)
        {
            var response = new CollectionResponse <Product>();

            try
            {
                var products = (string.IsNullOrEmpty(id)
                        ? _dacProduct.All()
                        : new[] { _dacProduct.Single(id) })
                               .ToList();

                response.Collections = products
                                       .Select(p => new Product
                {
                    Id     = p.Id,
                    Name   = p.Name,
                    Price  = p.Price,
                    Images = _dacProductImage
                             .Where(pi => pi.ProductId.Equals(p.Id))
                             .Select(pi => pi.Url)
                             .ToList(),
                    CategoryName = _dacProductCategory.Single(p.CategoryId)?
                                   .Name ?? string.Empty
                })
                                       .ToList();

                response.Status.SetSuccess();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                response.Status.SetError(e);
            }

            return(response);
        }