示例#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();
        }
 public ActionResult Edit(SaleInfoDTO item)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _service.UpdateSaleInfo(item);
             return(RedirectToAction("Statistics", "Home"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes!");
     }
     return(View(item));
 }
        public ChartInfo GetChartInfo(SaleInfoDTO saleInfo)
        {
            var       specificSaleInfo = GetSaleInfo().Where(x => x.ManagerName == saleInfo.ManagerName).ToList();
            ChartInfo chartInfo        = new ChartInfo();

            foreach (var item in specificSaleInfo)
            {
                if (!chartInfo.Products.Contains(item.ProductName))
                {
                    chartInfo.Products.Add(item.ProductName);
                    chartInfo.Count.Add(specificSaleInfo.Count(x => x.ProductName == item.ProductName) * item.ProductPrice);
                    chartInfo.Summ += (specificSaleInfo.Count(x => x.ProductName == item.ProductName) * item.ProductPrice);
                }
            }
            return(chartInfo);
        }
        public void UpdateSaleInfo(SaleInfoDTO item)
        {
            using (var transaction = Database.BeginTransaction())
            {
                try
                {
                    var updateMapperSaleInfo = new MapperConfiguration(cfg => cfg.CreateMap <SaleInfoDTO, SaleInfo>()
                                                                       .ForMember("SaleInfoId", opt => opt.MapFrom(s => s.SaleInfoId))
                                                                       .ForMember("ProductId", opt => opt.MapFrom(s => s.ProductId))
                                                                       .ForMember("ClientId", opt => opt.MapFrom(s => s.ClientId))
                                                                       .ForMember("ManagerId", opt => opt.MapFrom(s => s.ManagerId))
                                                                       .ForMember("DateOfSale", opt => opt.MapFrom(s => s.DateOfSale))).CreateMapper();
                    var updateItemSaleInfo = updateMapperSaleInfo.Map <SaleInfoDTO, SaleInfo>(item);
                    Database.SaleInfoRepository.Update(updateItemSaleInfo);

                    var updateMapperClient = new MapperConfiguration(cfg => cfg.CreateMap <SaleInfoDTO, Client>()
                                                                     .ForMember("ClientId", opt => opt.MapFrom(s => s.ClientId))
                                                                     .ForMember("Name", opt => opt.MapFrom(s => s.ClientName))).CreateMapper();
                    var updateItemClient = updateMapperClient.Map <SaleInfoDTO, Client>(item);
                    Database.ClientRepository.Update(updateItemClient);

                    var updateMapperProduct = new MapperConfiguration(cfg => cfg.CreateMap <SaleInfoDTO, Product>()
                                                                      .ForMember("ProductId", opt => opt.MapFrom(s => s.ProductId))
                                                                      .ForMember("Name", opt => opt.MapFrom(s => s.ProductName))
                                                                      .ForMember("Price", opt => opt.MapFrom(s => s.ProductPrice))).CreateMapper();
                    var updateItemProduct = updateMapperProduct.Map <SaleInfoDTO, Product>(item);
                    Database.ProductRepository.Update(updateItemProduct);

                    Database.Save();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Source + " : Crash in BLLService from UpdateSaleInfo");
                }
            }
        }
示例#5
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();
        }