Exemple #1
0
        public void AddSale(SaleInfoDTO saleInfo)
        {
            City city = new City {
                Name = saleInfo.CityName
            };

            Database.Cities.Create(city);

            Counterparty counterparty = new Counterparty {
                Name = saleInfo.CounterpartyName, City = city
            };

            Database.Counterparties.Create(counterparty);

            ContactOrganization contactOrganization = new ContactOrganization {
                Name = saleInfo.ContactOrganizationName
            };

            Database.ContactOrganizations.Create(contactOrganization);

            ContactSale contactSale = new ContactSale {
                Name = saleInfo.ContactSaleName
            };

            Database.ContactSales.Create(contactSale);

            Sale sale = new Sale {
                Name = saleInfo.Name, Counterparty = counterparty, ContactOrganization = contactOrganization, ContactSale = contactSale
            };

            Database.Sales.Create(sale);

            Database.Save();
        }
Exemple #2
0
        public void UpdateSale(SaleInfoDTO saleInfo)
        {
            var sale = Database.Sales.Get(saleInfo.Id);

            City city = new City {
                Name = saleInfo.CityName
            };

            Database.Cities.Create(city);

            Counterparty counterparty = new Counterparty {
                Name = saleInfo.CounterpartyName, City = city
            };

            Database.Counterparties.Create(counterparty);

            ContactOrganization contactOrganization = new ContactOrganization {
                Name = saleInfo.ContactOrganizationName
            };

            Database.ContactOrganizations.Create(contactOrganization);

            ContactSale contactSale = new ContactSale {
                Name = saleInfo.ContactSaleName
            };

            Database.ContactSales.Create(contactSale);

            sale.Name                = saleInfo.Name;
            sale.Counterparty        = counterparty;
            sale.ContactOrganization = contactOrganization;
            sale.ContactSale         = contactSale;
            Database.Sales.Update(sale);

            Database.Save();
        }
        protected override void Seed(SaleContext db)
        {
            var city1 = new City {
                Name = "Orenburg"
            };

            db.Cities.Add(city1);
            var city2 = new City {
                Name = "Tver"
            };

            db.Cities.Add(city2);

            var counerparty1 = new Counterparty {
                Name = "Roga i kopita", City = city2
            };

            db.Counterparties.Add(counerparty1);
            var counerparty2 = new Counterparty {
                Name = "Organization", City = city1
            };

            db.Counterparties.Add(counerparty2);

            var contactOrganization1 = new ContactOrganization {
                Name = "Ivanov"
            };

            db.ContactOrganizations.Add(contactOrganization1);
            var contactOrganization2 = new ContactOrganization {
                Name = "Petrov"
            };

            db.ContactOrganizations.Add(contactOrganization2);

            var contactSale1 = new ContactSale {
                Name = "Sidorov"
            };

            db.ContactSales.Add(contactSale1);
            var contactSale2 = new ContactSale {
                Name = "Animov"
            };

            db.ContactSales.Add(contactSale2);

            var sale1 = new Sale {
                Name = "Sale1", Counterparty = counerparty1, ContactOrganization = contactOrganization1, ContactSale = contactSale2
            };

            db.Sales.Add(sale1);
            var sale2 = new Sale {
                Name = "Sale2", Counterparty = counerparty1, ContactOrganization = contactOrganization2, ContactSale = contactSale1
            };

            db.Sales.Add(sale2);
            var sale3 = new Sale {
                Name = "Sale3", Counterparty = counerparty2, ContactOrganization = contactOrganization1, ContactSale = contactSale1
            };

            db.Sales.Add(sale3);



            db.SaveChanges();
        }