Exemple #1
0
        public static bool sendAlert(Stock s)
        {
            StockInventory db = new StockInventory();
            Stock          y  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.StockId == s.StockId);

            y.Quantity = y.LastRestockedQuantity;
            db.SaveChanges();
            return(true);
        }
Exemple #2
0
        public IHttpActionResult GetStockInventory(int id)
        {
            StockInventory stockInventory = db.Stock.Find(id);

            if (stockInventory == null)
            {
                return(NotFound());
            }

            return(Ok(stockInventory.Quantity));
        }
    public void Begin()
    {
        GetComponent <AudioSource>().Play();
        StockInventory inventory = GameObject.Find("StockDatabase").GetComponent <StockInventory>();

        while (inventory.numComp < 5)
        {
            Debug.Log("HI");
        }
        SceneManager.LoadSceneAsync("Game", LoadSceneMode.Single);
    }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     calendar = new[] { "Spring", "Summer", "Fall", "Winter" };
     timer    = 0;
     month    = 0;
     if (GameObject.Find("StockDatabase") != null)
     {
         inventory = GameObject.Find("StockDatabase").GetComponent <StockInventory>();
     }
     score = 0;
 }
Exemple #5
0
        public static Order findOrder(long v)
        {
            StockInventory db = new StockInventory();
            Order          o  = db.Orders.Include(x => x.Stock).Include(x => x.Stock.Product).Include(x => x.Vendor).Include(x => x.Company).FirstOrDefault(x => x.OrderId == v);

            if (o != null)
            {
                return(o);
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        public static Order printInvoice(long id)
        {
            StockInventory db = new StockInventory();
            Order          o  = db.Orders.FirstOrDefault(x => x.OrderId == id);

            if (o != null)
            {
                return(o);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public static Stock checkInventoryByStock(long id)
        {
            StockInventory db = new StockInventory();
            Stock          c  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.StockId == id);

            if (c != null)
            {
                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #8
0
        public static bool login(long eid, string pswd)
        {
            StockInventory db = new StockInventory();
            Employee       e  = db.Employees.FirstOrDefault(x => x.EmployeeId == eid && x.password == pswd);

            if (e != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static StockTransaction transact(long sid, int qua, string comment)
        {
            StockInventory   db = new StockInventory();
            StockTransaction st = new StockTransaction();
            Stock            s  = db.Stocks.Include("Product.Category").FirstOrDefault(x => x.StockId == sid);

            st.Stock          = s;
            st.comment        = comment;
            st.time           = DateTime.Now;
            st.QuantityBefore = s.Quantity;
            if (s.Quantity >= qua)
            {
                int x = Stock.deductStock(s.StockId, qua);
                if (x >= 0)
                {
                    try
                    {
                        st.QuantityAfter = x;
                        Stock m = st.Stock;
                        long  c = m.Product.ProductId;
                        st = db.StockTransactions.Add(st);
                        db.SaveChanges();
                        if (st != null)
                        {
                            return(st);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }
                }
            }
            return(null);
        }
        public IHttpActionResult PostStockInventory(StockInventory stockInventory)
        {
            StockInventory DbStockInventory = db.Stock.Find(stockInventory.ID);

            //
            DbStockInventory.Quantity = DbStockInventory.Quantity - 1;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = DbStockInventory.ID }, DbStockInventory));
        }
        public static long removeEntry(long stid)
        {
            StockInventory   db = new StockInventory();
            StockTransaction st = db.StockTransactions.FirstOrDefault(x => x.StockTransactionId == stid);

            if (st != null)
            {
                db.StockTransactions.Remove(st);
                db.SaveChanges();
                return(st.StockTransactionId);
            }
            else
            {
                return(0);
            }
        }
Exemple #12
0
        public static Category updateCategory(long id, string categoryName)
        {
            StockInventory db = new StockInventory();
            Category       c  = db.Categories.FirstOrDefault(x => x.CategoryId == id);

            if (c != null)
            {
                c.CategoryName = categoryName;
                db.SaveChanges();
                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #13
0
        public static bool deleteCategory(long id)
        {
            StockInventory db = new StockInventory();
            Category       c  = db.Categories.FirstOrDefault(x => x.CategoryId == id);

            if (c != null)
            {
                db.Categories.Remove(c);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
        public static Category addCategory(Category c)
        {
            StockInventory db = new StockInventory();
            Category       m  = db.Categories.FirstOrDefault(x => x.CategoryName == c.CategoryName);

            if (m == null)
            {
                m = db.Categories.Add(c);
                db.SaveChanges();
                return(m);
            }
            else
            {
                return(null);
            }
        }
Exemple #15
0
        public static bool deleteVendor(long id)
        {
            StockInventory db = new StockInventory();
            Vendor         c  = db.Vendors.FirstOrDefault(x => x.VendorId == id);

            if (c != null)
            {
                db.Vendors.Remove(c);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #16
0
        public static Vendor addVendor(Vendor c)
        {
            StockInventory db = new StockInventory();
            Vendor         m  = db.Vendors.FirstOrDefault(x => x.VendorName == c.VendorName);

            if (m == null)
            {
                m = db.Vendors.Add(c);
                db.SaveChanges();
                return(m);
            }
            else
            {
                return(null);
            }
        }
Exemple #17
0
        public static int setThreshold(long id, int limit)
        {
            StockInventory db = new StockInventory();
            Stock          s  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.StockId == id);

            if (s != null && limit != 0)
            {
                s.Threshold = limit;
                db.SaveChanges();
                return(s.Threshold);
            }
            else
            {
                return(0);
            }
        }
Exemple #18
0
        public static bool deleteProduct(long id)
        {
            StockInventory db = new StockInventory();
            Product        c  = db.Products.FirstOrDefault(x => x.ProductId == id);

            if (c != null)
            {
                db.Products.Remove(c);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #19
0
        public static int RevertStock(long id, int qua)
        {
            StockInventory db = new StockInventory();
            Stock          p  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.StockId == id);

            if (p != null)
            {
                p.Quantity = p.Quantity + qua;
                db.SaveChanges();
                return(p.Quantity);
            }
            else
            {
                return(0);
            }
        }
Exemple #20
0
        public static Company updateCompany(long id, Company p)
        {
            StockInventory db = new StockInventory();
            Company        c  = db.Companies.FirstOrDefault(x => x.CompanyId == id);

            if (c != null)
            {
                c.CompanyName    = p.CompanyName;
                c.CompanyEmail   = p.CompanyEmail;
                c.CompanyContact = p.CompanyContact;
                db.SaveChanges();
                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #21
0
        public static Stock addStock(Stock s)
        {
            StockInventory db = new StockInventory();
            Product        a  = db.Products.FirstOrDefault(x => x.ProductName == s.ProductName);
            Stock          p  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.ProductName == s.ProductName);

            if (p == null && a != null)
            {
                s.Product = a;
                p         = db.Stocks.Add(s);
                db.SaveChanges();
                return(p);
            }
            else
            {
                return(null);
            }
        }
        public IHttpActionResult AddStockInventory(StockInventory stock)
        {
            DAL.StockInventory model = new DAL.StockInventory();
            model.BracketNumber = 89;
            //model.ColumnNumber = 55;
            //model.ProductId = stock.ProductId;
            //model.ProductStyleId = stock.ProductStyleId;
            model.Quantity01 = stock.Quantity01;
            model.Quantity02 = stock.Quantity02;
            model.Quantity03 = stock.Quantity03;
            model.Quantity04 = stock.Quantity04;
            model.Quantity05 = stock.Quantity05;
            model.Quantity06 = stock.Quantity06;
            model.Quantity07 = stock.Quantity07;
            model.Quantity08 = stock.Quantity08;
            model.Quantity09 = stock.Quantity09;
            model.Quantity10 = stock.Quantity10;
            model.Quantity11 = stock.Quantity11;
            model.Quantity12 = stock.Quantity12;
            model.Quantity13 = stock.Quantity13;
            model.Quantity14 = stock.Quantity14;
            model.Quantity15 = stock.Quantity15;
            model.Quantity16 = stock.Quantity16;
            model.Quantity17 = stock.Quantity17;
            model.Quantity18 = stock.Quantity18;
            model.Quantity19 = stock.Quantity19;
            model.Quantity20 = stock.Quantity20;
            model.Quantity21 = stock.Quantity21;
            model.Quantity22 = stock.Quantity22;
            model.Quantity23 = stock.Quantity23;
            model.Quantity24 = stock.Quantity24;
            model.Quantity25 = stock.Quantity25;
            model.Quantity26 = stock.Quantity26;
            model.Quantity27 = stock.Quantity27;
            model.Quantity28 = stock.Quantity28;
            model.Quantity29 = stock.Quantity29;
            model.Quantity30 = stock.Quantity30;
            model.IsActive   = true;

            db.StockInventories.Add(stock);
            db.SaveChanges();
            return(Ok(true));
        }
Exemple #23
0
        public static Product updateProduct(long id, Product p)
        {
            StockInventory db = new StockInventory();
            Product        c  = db.Products.FirstOrDefault(x => x.ProductId == id);

            if (c != null)
            {
                c.ProductName = p.ProductName;
                c.Category    = db.Categories.FirstOrDefault(x => x.CategoryName == p.Category.CategoryName);
                c.Description = p.Description;
                c.size        = p.size;
                db.SaveChanges();
                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #24
0
        public static Product addProduct(Product p)
        {
            StockInventory db = new StockInventory();
            Category       c  = db.Categories.FirstOrDefault(x => x.CategoryName == p.Category.CategoryName);

            p.Category = c;
            Product m = db.Products.FirstOrDefault(x => x.ProductName == p.ProductName);

            if (m == null)
            {
                m = db.Products.Add(p);
                db.SaveChanges();
                return(m);
            }
            else
            {
                return(null);
            }
        }
Exemple #25
0
        public static Vendor updateVendor(long id, Vendor p)
        {
            StockInventory db = new StockInventory();
            Vendor         c  = db.Vendors.FirstOrDefault(x => x.VendorId == id);

            if (c != null)
            {
                c.VendorName    = p.VendorName;
                c.VendorEmail   = p.VendorEmail;
                c.VendorAddress = p.VendorAddress;
                c.VendorContact = p.VendorContact;
                db.SaveChanges();
                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #26
0
        public static Stock Restock(long id, Stock s)
        {
            StockInventory db = new StockInventory();
            Product        a  = db.Products.FirstOrDefault(x => x.ProductName == s.ProductName);
            Stock          p  = db.Stocks.FirstOrDefault(x => x.StockId == id);

            if (p != null && a != null)
            {
                p.shelf                 = s.shelf;
                p.Threshold             = s.Threshold;
                p.LastRestockedDate     = s.LastRestockedDate;
                p.LastRestockedQuantity = s.LastRestockedQuantity;
                p.Quantity              = s.Quantity;
                p.UnitPrice             = s.UnitPrice;
                db.SaveChanges();
                return(p);
            }
            else
            {
                return(null);
            }
        }
Exemple #27
0
        public static int deductStock(long id, int qua)
        {
            StockInventory db = new StockInventory();
            Stock          p  = db.Stocks.Include(x => x.Product.Category).FirstOrDefault(x => x.StockId == id);

            if (p != null && p.Quantity >= qua)
            {
                try
                {
                    p.Quantity = p.Quantity - qua;
                    if (p.Quantity <= p.Threshold)
                    {
                        //sendAlert(p);
                    }
                    db.SaveChanges();
                    return(p.Quantity);
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage);
                        }
                        Debug.WriteLine("- Property: \"{0}\"", p.Product.ProductName);
                    }
                    throw;
                }
            }
            else
            {
                return(0);
            }
        }
Exemple #28
0
        public static bool cancelOrder(long id)
        {
            StockInventory db = new StockInventory();
            Order          o  = db.Orders.Include(x => x.Stock).FirstOrDefault(x => x.OrderId == id);
            Stock          a  = db.Stocks.Include("Product").FirstOrDefault(x => x.StockId == o.Stock.StockId);

            if (o != null)
            {
                if ((a.Quantity - o.Quantity) >= 0)
                {
                    a.Quantity = a.Quantity - o.Quantity;
                    a.LastRestockedQuantity = a.Quantity;
                    db.Orders.Remove(o);
                    db.SaveChanges();
                    return(true);
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }
Exemple #29
0
        public static Order placeOrder(Stock p, int qua, Vendor v, Company c)
        {
            StockInventory db = new StockInventory();
            Stock          a  = db.Stocks.Include("Product").FirstOrDefault(x => x.Product.ProductId == p.Product.ProductId);
            Company        m  = Company.findCompany(c.CompanyId);
            Vendor         n  = Vendor.findVendor(v.VendorId);
            Order          o  = new Order {
                Stock = a, Quantity = qua, Vendor = n, Company = m, OrderDate = DateTime.Now, Status = "confirmed"
            };

            o = db.Orders.Add(o);
            if (a != null && o != null)
            {
                a.Quantity = a.Quantity + qua;
                a.LastRestockedQuantity = a.Quantity;
                db.SaveChanges();
                return(o);
            }
            else
            {
                return(null);
            }
        }
        public static StockTransaction findStocktransactionByID(long id)
        {
            StockInventory db = new StockInventory();

            return(db.StockTransactions.Include("Stock").Include("Stock.Product.Category").FirstOrDefault(x => x.StockTransactionId == id));
        }