コード例 #1
0
        public static void AddShop(BusinessDbContext context, string shop1Id, string name)
        {
            Shop demo1 = new Shop()
            {
                Id               = shop1Id,
                Name             = name,
                Phone            = name,
                Created          = DateTime.Now,
                Modified         = DateTime.Now,
                CreatedBy        = "*****@*****.**",
                ModifiedBy       = "*****@*****.**",
                CreatedFrom      = "System",
                RegistrationDate = DateTime.Today.Date,
                ExpiryDate       = new DateTime(2020, 1, 1),
                IsVerified       = true,
                IsActive         = true,
                TotalUsers       = 1,
                District         = "Dhaka",
                Website          = "http://www.bizbook365.com",
            };

            if (ShopNotExists(context, demo1))
            {
                context.Shops.Add(demo1);
                context.SaveChanges();
            }
        }
コード例 #2
0
        public static void AddWarehouse(BusinessDbContext db, string shopId)
        {
            Warehouse warehouse = db.Warehouses.FirstOrDefault(x => x.ShopId == shopId && x.Name == "Default");

            if (warehouse == null)
            {
                warehouse = new Warehouse()
                {
                    Id          = Guid.NewGuid().ToString(),
                    Created     = DateTime.Now,
                    Modified    = DateTime.Now,
                    ShopId      = shopId,
                    CreatedBy   = "System",
                    ModifiedBy  = "System",
                    CreatedFrom = "System",
                    Name        = "Default",
                    IsActive    = true,
                    Area        = "Default",
                    District    = "",
                    IsMain      = true,
                };

                db.Warehouses.Add(warehouse);
                db.SaveChanges();
            }
        }
コード例 #3
0
        public static void AddProducts(BusinessDbContext context, string shopId)
        {
            ProductGroup group = GetDefaults <ProductGroup>(shopId);

            group.Name = "Food";
            bool any = context.ProductGroups.Any(x => x.ShopId == shopId && x.Name == @group.Name);

            if (!any)
            {
                context.ProductGroups.Add(group);
                context.SaveChanges();
            }

            ProductCategory category = GetDefaults <ProductCategory>(shopId);

            category.ProductGroupId = group.Id;
            category.Name           = "Snacks";

            any = context.ProductCategories.Any(x => x.ShopId == shopId && x.Name == category.Name);
            if (!any)
            {
                context.ProductCategories.Add(category);
                context.SaveChanges();
            }

            ProductDetail detail = GetDefaults <ProductDetail>(shopId);

            detail.ProductCategoryId = category.Id;
            detail.Name      = "Biscuit";
            detail.BarCode   = Guid.NewGuid().ToString();
            detail.BrandId   = shopId;
            detail.CostPrice = 20.00;
            detail.SalePrice = 50;
            // new added
            detail.ProductCode = Guid.NewGuid().ToString();


            any = context.ProductDetails.Any(x => x.ShopId == shopId && x.Name == detail.Name);
            if (!any)
            {
                context.ProductDetails.Add(detail);
                context.SaveChanges();
            }
        }
コード例 #4
0
        //public static void AddDemo1Shop(BusinessDbContext context, string shop1Id, string name)
        //{
        //    if (ShopNotExists(context, new Shop() { Id = shop1Id, Name = name }))
        //    {
        //        AddShop(context, shop1Id, name);
        //    }
        //}

        public static void AddSysShop(BusinessDbContext context)
        {
            Shop sysShop       = GetSysShop();
            var  shopNotExists = ShopNotExists(context, sysShop);

            if (shopNotExists)
            {
                context.Shops.Add(sysShop);
                context.SaveChanges();
            }
        }
コード例 #5
0
        public static void AddSupplier(string shopId, BusinessDbContext context, string name = "Code Coopers")
        {
            Supplier supplier = GetDefaults <Supplier>(shopId);

            supplier.Name  = name;
            supplier.Phone = shopId;

            if (!context.Suppliers.Any(x => x.Id == shopId))
            {
                context.Suppliers.Add(supplier);
                context.SaveChanges();
            }
        }
コード例 #6
0
        public static void AddBrand(string shopId, BusinessDbContext context, string name = "Code Coopers")
        {
            Brand b = GetDefaults <Brand>(shopId);

            b.Name  = name;
            b.Phone = shopId;

            if (!context.Brands.Any(x => x.Id == shopId))
            {
                context.Brands.Add(b);
                context.SaveChanges();
            }
        }
コード例 #7
0
        public static void AddSupplier(BusinessDbContext context, string shopId)
        {
            Supplier supplier = GetDefaults <Supplier>(shopId);

            supplier.Name  = "Food Valley";
            supplier.Phone = "ph123";
            var any = context.Suppliers.Any(x => x.ShopId == shopId && x.Name == supplier.Name);

            if (!any)
            {
                context.Suppliers.Add(supplier);
                context.SaveChanges();
            }
        }
コード例 #8
0
        public static void AddCustomer(BusinessDbContext context, string shopId)
        {
            Customer customer = GetDefaults <Customer>(shopId);

            customer.Phone            = "0";
            customer.Name             = "Anon";
            customer.MembershipCardNo = shopId;
            bool any = context.Customers.Any(x => x.ShopId == shopId && x.Phone == customer.Phone);

            if (!any)
            {
                context.Customers.Add(customer);
                context.SaveChanges();
            }
        }
コード例 #9
0
        public static void AddWallet(BusinessDbContext context, string shopId)
        {
            bool exists = context.Wallets.Any(x => x.AccountTitle == "Cash" && x.ShopId == shopId);

            if (!exists)
            {
                Wallet info = GetDefaults <Wallet>(shopId);
                info.Id            = Guid.NewGuid().ToString();
                info.AccountTitle  = "Cash";
                info.WalletType    = WalletType.Cash;
                info.AccountNumber = "Cash";

                context.Wallets.Add(info);
                context.SaveChanges();
            }
        }
コード例 #10
0
        public static void AddAccountHeads(BusinessDbContext context, string shopId)
        {
            var heads = GetAccountHeads();

            foreach (string head in heads)
            {
                if (context.AccountHeads.Any(x => x.Name.ToUpper().Contains(head) && x.ShopId == shopId))
                {
                    continue;
                }

                AccountHead accountHead = GetDefaults <AccountHead>(shopId);
                accountHead.Id   = Guid.NewGuid().ToString();
                accountHead.Name = head;
                context.AccountHeads.Add(accountHead);
                context.SaveChanges();
            }
        }
コード例 #11
0
        public static void UpdateSaleDetailType(BusinessDbContext context)
        {
            int executeSqlCommand = context.Database.ExecuteSqlCommand("update SaleDetails set SaleDetailType = 1 where SaleDetailType = 0");

            context.SaveChanges();
        }
コード例 #12
0
        public static void UpdateWarehouseRelatedData(BusinessDbContext context)
        {
            List <string> ids = context.Shops.Where(x => x.IsActive).Select(x => x.Id).ToList();

            foreach (var shopId in ids)
            {
                var whId      = context.Warehouses.First(x => x.ShopId == shopId).Id;
                var purchases = context.Purchases.Where(x => x.ShopId == shopId && x.WarehouseId == null).ToList();
                foreach (var item in purchases)
                {
                    item.WarehouseId = whId;
                }

                context.SaveChanges();
                var purchaseDetails = context.PurchaseDetails.Where(x => x.ShopId == shopId && x.WarehouseId == null)
                                      .ToList();
                foreach (var item in purchaseDetails)
                {
                    item.WarehouseId = whId;
                }

                context.SaveChanges();

                var sales = context.Sales.Where(x => x.ShopId == shopId && x.WarehouseId == null).ToList();
                foreach (var item in sales)
                {
                    item.WarehouseId = whId;
                }

                context.SaveChanges();

                var saleDetails = context.SaleDetails.Where(x => x.ShopId == shopId && x.WarehouseId == null).ToList();
                foreach (var item in saleDetails)
                {
                    item.WarehouseId = whId;
                }

                var productDetails = context.ProductDetails.Where(x => x.ShopId == shopId && x.IsActive).ToList();
                foreach (var item in productDetails)
                {
                    WarehouseProduct whProduct = context.WarehouseProducts.FirstOrDefault(
                        x => x.ShopId == shopId && x.ProductDetailId == item.Id && x.WarehouseId == whId);
                    if (whProduct != null)
                    {
                        continue;
                    }

                    whProduct = new WarehouseProduct()
                    {
                        Id                   = Guid.NewGuid().ToString(),
                        Created              = DateTime.Now,
                        Modified             = DateTime.Now,
                        ShopId               = shopId,
                        CreatedBy            = "System",
                        ModifiedBy           = "System",
                        CreatedFrom          = "System",
                        IsActive             = true,
                        ProductDetailId      = item.Id,
                        StartingInventory    = item.StartingInventory,
                        Purchased            = item.Purchased,
                        Sold                 = item.Sold,
                        OnHand               = item.OnHand,
                        MinimumStockToNotify =
                            item.MinimumStockToNotify,
                        TransferredIn  = 0,
                        TransferredOut = 0,
                        WarehouseId    = whId
                    };

                    context.WarehouseProducts.Add(whProduct);
                    context.SaveChanges();
                }
            }
        }