Пример #1
0
        public void AddSaleInfo(SaleInfo_BL saleInfo_BL)
        {
            lock (locker)
            {
                var manager = new DAL.Data.Manager_DAL()
                {
                    SecondName = saleInfo_BL.Manager
                };
                var client = new DAL.Data.Client_DAL()
                {
                    FullName = saleInfo_BL.Client
                };
                var product = new DAL.Data.Product_DAL()
                {
                    Name = saleInfo_BL.Product
                };

                var managerId = repositories.Managers.GetId(manager);
                if (managerId == null)
                {
                    repositories.Managers.Add(manager);
                    repositories.Save();
                    managerId = repositories.Managers.GetId(manager);
                }

                var clientId = repositories.Clients.GetId(client);
                if (clientId == null)
                {
                    repositories.Clients.Add(client);
                    repositories.Save();
                    clientId = repositories.Clients.GetId(client);
                }

                var productId = repositories.Products.GetId(product);
                if (productId == null)
                {
                    repositories.Products.Add(product);
                    repositories.Save();
                    productId = repositories.Products.GetId(product);
                }

                var saleInfo = new DAL.Data.SaleInfo_DAL()
                {
                    Date      = saleInfo_BL.Date,
                    ManagerId = (int)managerId,
                    ClientId  = (int)clientId,
                    ProductId = (int)productId,
                    PriceSum  = saleInfo_BL.PriceSum
                };

                repositories.SalesInfo.Add(saleInfo);
                repositories.Save();

                //Console.WriteLine("delay 2000");
                //Thread.Sleep(2000);
            }
        }
Пример #2
0
        public void UpdateSaleInfo(SaleInfo_BL saleInfo_BL)
        {
            var manager = new DAL.Data.Manager_DAL {
                SecondName = saleInfo_BL.Manager
            };
            var client = new DAL.Data.Client_DAL()
            {
                FullName = saleInfo_BL.Client
            };
            var product = new DAL.Data.Product_DAL()
            {
                Name = saleInfo_BL.Product
            };

            var managerId = repositories.Managers.GetId(manager);

            if (managerId == null)
            {
                repositories.Managers.Add(manager);
                repositories.Save();
                managerId = repositories.Managers.GetId(manager);
            }

            var clientId = repositories.Clients.GetId(client);

            if (clientId == null)
            {
                repositories.Clients.Add(client);
                repositories.Save();
                clientId = repositories.Clients.GetId(client);
            }

            var productId = repositories.Products.GetId(product);

            if (productId == null)
            {
                repositories.Products.Add(product);
                repositories.Save();
                productId = repositories.Products.GetId(product);
            }

            var saleInfo = new DAL.Data.SaleInfo_DAL()
            {
                Date      = saleInfo_BL.Date,
                ManagerId = (int)managerId,
                ClientId  = (int)clientId,
                ProductId = (int)productId,
                PriceSum  = saleInfo_BL.PriceSum
            };

            var sale = repositories.SalesInfo.GetAll().FirstOrDefault(s => (s.Id == saleInfo_BL.Id));

            sale.Date      = saleInfo_BL.Date;
            sale.ManagerId = (int)managerId;
            sale.ClientId  = (int)clientId;
            sale.ProductId = (int)productId;
            sale.PriceSum  = saleInfo_BL.PriceSum;

            repositories.SalesInfo.Update(sale);
            repositories.Save();
        }