Exemplo n.º 1
0
        public void SaveProductPhoto(int productId, string photoname, byte[] photo)
        {
            _context.BeginTransaction();

            var productPhoto = new ModelStore <ProductPhoto>()
                               .TrackChanges(ChangeTrackingStrategy.PropertyState);

            productPhoto.Add(new ProductPhoto()
            {
                ProductPhotoID     = productId,
                LargePhotoFileName = photoname,
                LargePhoto         = photo
            });

            var result = productPhoto.SaveChanges(_context);

            if (result.InsertedCount == 1)
            {
                var productPhotoID = productPhoto.FirstOrDefault().ProductPhotoID;

                var pordProdPhoto = new ModelStore <ProductProductPhoto>()
                                    .TrackChanges(ChangeTrackingStrategy.PropertyState);
                pordProdPhoto.Add(new ProductProductPhoto()
                {
                    ProductID      = productId,
                    ProductPhotoID = productPhotoID,
                    Primary        = 1
                });

                pordProdPhoto.SaveChanges(_context);
            }

            _context.Commit();
        }
        public IModelStore <SubCategorySalesReport> RetrieveSubCategorySalesReport(params object[] salesmonth)
        {
            var OrderReportMonth1 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[1]);
            var OrderReportMonth2 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[2]);
            var OrderReportMonth3 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[3]);
            var OrderReportMonth4 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[4]);
            var OrderReportMonth5 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[5]);
            var OrderReportMonth6 = Retrieve <SubCategorySalesReport_D>(salesmonth[0], salesmonth[6]);

            var modelStore             = new ModelStore <SubCategorySalesReport>();
            var subCategorySalesReport = new SubCategorySalesReport();

            if (OrderReportMonth1.Count > 0)
            {
                subCategorySalesReport.Name = OrderReportMonth1.GetValue <string>(0, "SubcategoryName");

                subCategorySalesReport.SalesqtyMonth1  = OrderReportMonth1.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth1 = OrderReportMonth1.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            if (OrderReportMonth2.Count > 0)
            {
                subCategorySalesReport.SalesqtyMonth2  = OrderReportMonth2.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth2 = OrderReportMonth2.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            if (OrderReportMonth3.Count > 0)
            {
                subCategorySalesReport.SalesqtyMonth3  = OrderReportMonth3.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth3 = OrderReportMonth3.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            if (OrderReportMonth4.Count > 0)
            {
                subCategorySalesReport.SalesqtyMonth4  = OrderReportMonth4.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth4 = OrderReportMonth4.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            if (OrderReportMonth5.Count > 0)
            {
                subCategorySalesReport.SalesqtyMonth5  = OrderReportMonth5.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth5 = OrderReportMonth5.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            if (OrderReportMonth6.Count > 0)
            {
                subCategorySalesReport.SalesqtyMonth6  = OrderReportMonth6.GetValue <int?>(0, "TotalSalesqty") ?? 0;
                subCategorySalesReport.SalesRoomMonth6 = OrderReportMonth6.GetValue <decimal?>(0, "TotalSaleroom") ?? 0;
            }

            modelStore.Add(subCategorySalesReport);

            return(modelStore);
        }
Exemplo n.º 3
0
        public int SavePerson(IModelStore <Person> person,
                              IModelStore <BusinessEntityAddress> addresses,
                              IModelStore <PersonPhone> phones,
                              IModelStore <Customer> customers)
        {
            int intPersonId = 0;

            _context.BeginTransaction();

            if (person.TrackedCount(StateTrackable.NewModified) == 1)
            {
                var businessEntity = new ModelStore <BusinessEntity>()
                                     .TrackChanges(ChangeTrackingStrategy.PropertyState);

                businessEntity.Add(new BusinessEntity()
                {
                    ModifiedDate = DateTime.Now
                });

                var result = businessEntity.SaveChanges(_context);

                if (result.InsertedCount == 1)
                {
                    intPersonId = businessEntity.FirstOrDefault().BusinessEntityID;
                    person.SetValue(0, "Businessentityid", intPersonId);
                }
            }
            else
            {
                intPersonId = person.FirstOrDefault().Businessentityid;
            }


            SetPrimaryKey(person, addresses, phones, customers);

            //Save person address, phone, customer
            person.SaveChanges(_context);
            addresses.SaveChanges(_context);
            phones.SaveChanges(_context);
            customers.SaveChanges(_context);

            _context.Commit();

            return(intPersonId);
        }