public static void SaveSale(Sale sale)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Sales.Add(sale);
                retailDbContext.SaveChanges(); //This will give us a unique SaleID

                //QtyOnHand change
                foreach (Saleline sl in sale.Salelines)
                {
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == sl.ProductID) && (x.StoreID == sale.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct            = new StoreProduct();
                        storeProduct.ProductID  = sl.ProductID;
                        storeProduct.StoreID    = sale.StoreID;
                        storeProduct.QtyOnHand -= sl.Quantity;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        storeProduct.QtyOnHand -= sl.Quantity;
                    }

                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "S";
                    storeProductTran.DocumentID    = sale.SaleID;
                    storeProductTran.Quantity      = sl.Quantity;
                    storeProductTran.EffectiveTime = sale.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
        public static void SaveGrn(Grn grn)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Grns.Add(grn);
                retailDbContext.SaveChanges(); //This will give us a unique GrnID

                //QtyOnHand change
                foreach (Grnline gl in grn.Grnlines)
                {
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == gl.ProductID) && (x.StoreID == grn.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct            = new StoreProduct();
                        storeProduct.ProductID  = gl.ProductID;
                        storeProduct.StoreID    = grn.StoreID;
                        storeProduct.QtyOnHand += gl.Quantity;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        storeProduct.QtyOnHand += gl.Quantity;
                    }

                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "G";
                    storeProductTran.DocumentID    = grn.GrnID;
                    storeProductTran.Quantity      = gl.Quantity;
                    storeProductTran.EffectiveTime = grn.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
 public static void SaveProduct(Product product)
 {
     using (RetailDbContext retailDbContext = new RetailDbContext())
     {
         retailDbContext.Products.Add(product);
         retailDbContext.SaveChanges();
     }
 }
Example #4
0
        public bool LoginUser(string userCode, string password)
        {
            UserCode = userCode;
            Password = password;

            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                User user = retailDbContext.Users.Where(x => x.UserCode == userCode).FirstOrDefault();
                if (user == null)
                {
                    ulResult = ULResult.NoUserCode;
                    return(false);
                }
                else
                {
                    UserID = user.UserID;
                    if (user.Password != password)
                    {
                        ulResult = ULResult.IncorrectPassword;
                        return(false);
                    }
                    else
                    {
                        Employee emp = retailDbContext.Employees.Where(x => x.UserID == UserID).FirstOrDefault();
                        if (emp == null)
                        {
                            ulResult = ULResult.EmpNotFound;
                            return(false);
                        }
                        else
                        {
                            EmployeeID = emp.EmployeeID;
                            return(true);
                        }
                    }
                }
            }
        }
        public static void SaveStocktake(Stocktake st)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Stocktakes.Add(st);
                retailDbContext.SaveChanges(); //This will give us a unique StocktakeID

                //QtyOnHand change
                foreach (Stocktakeline stl in st.Stocktakelines)
                {
                    int          QtyBefore    = 0;
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == stl.ProductID) && (x.StoreID == st.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct           = new StoreProduct();
                        storeProduct.ProductID = stl.ProductID;
                        storeProduct.StoreID   = st.StoreID;
                        storeProduct.QtyOnHand = stl.CountedQty;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        QtyBefore = storeProduct.QtyOnHand;
                        storeProduct.QtyOnHand = stl.CountedQty;
                    }

                    //QtyOnHand change history
                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "A";
                    storeProductTran.DocumentID    = st.StocktakeID;
                    storeProductTran.Quantity      = stl.CountedQty - QtyBefore;
                    storeProductTran.EffectiveTime = st.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
        public static List <Supplier> GetSuppliers()
        {
            RetailDbContext retailDbContext = new RetailDbContext();

            return(retailDbContext.Suppliers.ToList());
        }
        public static List <Employee> GetEmployees()
        {
            RetailDbContext retailDbContext = new RetailDbContext();

            return(retailDbContext.Employees.ToList());
        }
        public static List <Customer> GetCustomers()
        {
            RetailDbContext retailDbContext = new RetailDbContext();

            return(retailDbContext.Customers.ToList());
        }
        public static List <Product> GetProducts()
        {
            RetailDbContext retailDbContext = new RetailDbContext();

            return(retailDbContext.Products.ToList());
        }
        public static List <Sale> GetSales()
        {
            RetailDbContext retailDbContext = new RetailDbContext();

            return(retailDbContext.Sales.Include("Salelines").ToList());
        }