Exemplo n.º 1
0
        private Sale ToObject(SalesData.Sale sale)
        {
            var objectSale = new Sale(sale.SaleID, ToObject(sale.Manager), ToObject(sale.Client), ToObject(sale.Product), sale.SaleDate);

            return objectSale;
        }
Exemplo n.º 2
0
 public void AddSale(Sale sale)
 {
     var eSale= ToEntity(sale);
     _salesDataContext.Sales.Add(eSale);
 }
Exemplo n.º 3
0
        private SalesData.Sale ToEntity(Sale sale)
        {
            var manager = _salesDataContext.Managers.Any(m => m.MangerName == sale.Manager.Name)
                ? _salesDataContext.Managers.First(m => m.MangerName == sale.Manager.Name)
                : ToEntity(sale.Manager);

            var client = _salesDataContext.Clients.Any(c => c.ClientName == sale.Client.Name)
                ? _salesDataContext.Clients.First(c => c.ClientName == sale.Client.Name)
                : ToEntity(sale.Client);

            var product = _salesDataContext.Products.Any(p => p.ProductName == sale.Product.ProductName && p.ProductCost == sale.Product.Cost)
                ? _salesDataContext.Products.First(p => p.ProductName == sale.Product.ProductName && p.ProductCost == sale.Product.Cost)
                : ToEntity(sale.Product);

            var entitySale = new SalesData.Sale()
            {
                SaleID = sale.Id,
                Manager = manager,
                Client = client,
                Product = product,
                SaleDate = sale.SaleDate
            };

            return entitySale;
        }