public object removeCustomerOrderProduct(int productID, int customerorderID, int quantity)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault();
                if (product != null)
                {
                    Customer_Order customerorder = db.Customer_Order.Where(x => x.CustomerOrderID == customerorderID).FirstOrDefault();
                    if (customerorder != null)
                    {
                        Product_Backlog backlog_Product = db.Product_Backlog.Where(x => x.ContainerID == customerorder.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                        if (backlog_Product != null)
                        {
                            backlog_Product.QuantityToOrder = (backlog_Product.QuantityToOrder - quantity);
                            db.SaveChanges();

                            Product_Order_Line product_Order = db.Product_Order_Line.Where(x => x.ProductID == product.ProductID && x.CustomerOrderID == customerorder.CustomerOrderID).FirstOrDefault();
                            if (product_Order != null)
                            {
                                db.Product_Order_Line.Remove(product_Order);
                                db.SaveChanges();

                                toReturn.Product_Order_Line = product_Order;
                            }
                        }
                        else
                        {
                            toReturn.Error = "Container Not Found";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Order Not Found";
                    }
                }
                else
                {
                    toReturn.Error = "Product Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Product Removal Unsuccessful";
            }

            return(toReturn);
        }
        public object cancelCustomerOrder(int customerorderID)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                //get sale
                Customer_Order newCustomerOrder = db.Customer_Order.Where(x => x.CustomerOrderID == customerorderID).FirstOrDefault();
                if (newCustomerOrder != null)
                {
                    //get container
                    Container container = db.Containers.Where(x => x.ContainerID == newCustomerOrder.ContainerID).FirstOrDefault();



                    //get list of products in Sale
                    List <Product_Order_Line> product_Order_line = newCustomerOrder.Product_Order_Line.ToList();

                    if (container != null)
                    {
                        if (product_Order_line != null)
                        {
                            foreach (var prod in product_Order_line)
                            {
                                Product product = db.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();
                                if (product != null)
                                {
                                    Product_Backlog backlog_Product = db.Product_Backlog.Where(x => x.ContainerID == newCustomerOrder.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                                    if (backlog_Product != null)
                                    {
                                        backlog_Product.QuantityToOrder = (backlog_Product.QuantityToOrder + prod.PLQuantity);
                                        db.SaveChanges();

                                        Product_Order_Line product_Order_Line = db.Product_Order_Line.Where(x => x.ProductID == product.ProductID && x.CustomerOrderID == newCustomerOrder.CustomerOrderID).FirstOrDefault();
                                        if (product_Order_Line != null)
                                        {
                                            db.Product_Order_Line.Remove(product_Order_Line);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                else
                                {
                                    toReturn.Error = "Product Not Found";
                                }
                            }

                            toReturn.Message = "Order Cancelled";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Container Not Found";
                    }
                }


                else
                {
                    toReturn.Error = "Cancel Failed: Order Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Customer Order Cancellation Unsuccessfully Completed";
            }

            return(toReturn);
        }
        public object addCustomerOrderProduct(int productID, int customerorderID, int quantity)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault();
                if (product != null)
                {
                    Customer_Order customerorder = db.Customer_Order.Where(x => x.CustomerOrderID == customerorderID).FirstOrDefault();
                    if (customerorder != null)
                    {
                        Product_Backlog backlog_Product = db.Product_Backlog.Where(x => x.ContainerID == customerorder.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                        if (backlog_Product != null)
                        {
                            backlog_Product.QuantityToOrder = (backlog_Product.QuantityToOrder + quantity);
                            db.SaveChanges();

                            Product_Order_Line product_Order_Line = db.Product_Order_Line.Where(x => x.ProductID == product.ProductID && x.CustomerOrderID == customerorder.CustomerOrderID).FirstOrDefault();
                            if (product_Order_Line == null)
                            {
                                Product_Order_Line newProduct_Order_Line = new Product_Order_Line();
                                newProduct_Order_Line.ProductID       = product.ProductID;
                                newProduct_Order_Line.Product         = product;
                                newProduct_Order_Line.CustomerOrderID = customerorder.CustomerOrderID;
                                newProduct_Order_Line.Customer_Order  = customerorder;
                                newProduct_Order_Line.PLQuantity      = quantity;
                                db.Product_Order_Line.Add(newProduct_Order_Line);
                                db.SaveChanges();

                                toReturn.Product_Order_Line = db.Product_Order_Line.ToList().LastOrDefault();
                            }
                            else
                            {
                                product_Order_Line.PLQuantity = product_Order_Line.PLQuantity + quantity;
                                db.SaveChanges();

                                toReturn.Product_Order_Line = product_Order_Line;
                            }
                        }
                        else
                        {
                            toReturn.Error = "Container Not Found";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Order Not Found";
                    }
                }
                else
                {
                    toReturn.Error = "Product Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Product Add Unsuccessful";
            }

            return(toReturn);
        }
Exemple #4
0
        public object cancelSupplierOrder(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            toReturn.supplierOrder = new ExpandoObject();


            try
            {
                Supplier_Order order = db.Supplier_Order.Where(x => x.SupplierOrderID == id).FirstOrDefault();

                if (order != null)
                {
                    if (order.SupplierOrderStatusID == 2)
                    {
                        toReturn.Message = "Supplier Order Was Already Cancelled";
                        return(toReturn);
                    }

                    if (order.SupplierOrderStatusID == 3 || order.SupplierOrderStatusID == 4)
                    {
                        toReturn.Message = "Delivered BackOrderd Orders Cannot Be Cancel";
                    }
                    else
                    {
                        Supplier_Order_Status status = db.Supplier_Order_Status.Where(x => x.SupplierOrderStatusID == 2).FirstOrDefault();
                        order.SupplierOrderStatusID = status.SupplierOrderStatusID;
                        order.Supplier_Order_Status = status;
                        db.SaveChanges();

                        List <Supplier_Order_Product> order_Products = db.Supplier_Order_Product.Where(x => x.SupplierOrderID == id).ToList();
                        foreach (Supplier_Order_Product prod in order_Products)
                        {
                            //get product details
                            Product product = db.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();

                            //get the backlog details of the product so we can add back the quantity
                            Product_Backlog backlog = db.Product_Backlog.Where(x => x.ProductID == product.ProductID && x.ContainerID == order.ContainerID).FirstOrDefault();
                            if (backlog != null)
                            {
                                //add back the quantity
                                backlog.QuantityToOrder = backlog.QuantityToOrder + prod.SOPQuantityOrdered;
                                backlog.DateModified    = DateTime.Now;
                                db.SaveChanges();
                            }
                            else
                            {
                                //if no backlog record exits, create a new
                                Product_Backlog backlog1 = new Product_Backlog();
                                backlog1.ProductID       = product.ProductID;
                                backlog1.QuantityToOrder = prod.SOPQuantityOrdered;
                                backlog1.DateModified    = DateTime.Now;
                                backlog1.ContainerID     = order.ContainerID;
                                db.Product_Backlog.Add(backlog1);
                                db.SaveChanges();
                            }
                        }
                    }


                    toReturn.Message = "Supplier Order Successfuly Cancelled";
                }
                else
                {
                    toReturn.Error = "Supplier Order Not Found";
                }
            }

            catch
            {
                toReturn.Error = "Search Interrupted. Retry";
            }

            return(toReturn);
        }
Exemple #5
0
        public object placeSupplierOrder(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            toReturn.supplierOrder = new ExpandoObject();


            try
            {
                Supplier_Order order = db.Supplier_Order.Where(x => x.SupplierOrderID == id).FirstOrDefault();

                if (order != null)
                {
                    Supplier_Order_Status status = db.Supplier_Order_Status.Where(x => x.SupplierOrderStatusID == 1).FirstOrDefault();
                    order.SupplierOrderStatusID = status.SupplierOrderStatusID;
                    db.SaveChanges();

                    List <Supplier_Order_Product> order_Products = db.Supplier_Order_Product.Where(x => x.SupplierOrderID == id).ToList();
                    foreach (Supplier_Order_Product prod in order_Products)
                    {
                        //get product details
                        Product product = db.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();

                        //get the backlog details of the product so we can add back the quantity
                        Product_Backlog backlog = db.Product_Backlog.Where(x => x.ProductID == product.ProductID && x.ContainerID == order.ContainerID).FirstOrDefault();
                        if (backlog != null)
                        {
                            //remove back the quantity
                            if (backlog.QuantityToOrder < prod.SOPQuantityOrdered)
                            {
                                backlog.QuantityToOrder = 0;
                                backlog.DateModified    = DateTime.Now;
                                db.SaveChanges();
                            }
                            else
                            {
                                backlog.QuantityToOrder = backlog.QuantityToOrder - prod.SOPQuantityOrdered;
                                backlog.DateModified    = DateTime.Now;
                                db.SaveChanges();
                            }
                        }
                    }



                    toReturn.Message = this.sendEmail(id);
                }
                else
                {
                    toReturn.Error = "Supplier Order Details Not Found";
                }
            }

            catch
            {
                toReturn.Error = "Search Interrupted. Retry";
            }

            return(toReturn);
        }
        public object DeleteContainer(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Container objectContainer = new Container();
            dynamic   toReturn        = new ExpandoObject();

            try
            {
                objectContainer = db.Containers.Find(id);

                if (objectContainer == null)
                {
                    toReturn.Message = "Record Not Found";
                }
                else
                {
                    User user                = db.Users.Where(x => x.ContainerID == id).FirstOrDefault();
                    Container_Product con    = db.Container_Product.Where(x => x.ContainerID == id).FirstOrDefault();
                    Sale            sale     = db.Sales.Where(x => x.ContainerID == id).FirstOrDefault();
                    Customer_Order  order    = db.Customer_Order.Where(x => x.ContainerID == id).FirstOrDefault();
                    Supplier_Order  suporder = db.Supplier_Order.Where(x => x.ContainerID == id).FirstOrDefault();
                    Product_Backlog prod     = db.Product_Backlog.Where(x => x.ContainerID == id).FirstOrDefault();
                    if (user == null && con == null && sale == null && order == null && suporder == null && prod == null)
                    {
                        List <Manager> managers = db.Managers.ToList();
                        if (managers.Count != 0)
                        {
                            foreach (Manager man in managers)
                            {
                                List <Container> containers = man.Containers.ToList();
                                foreach (Container container in containers)
                                {
                                    if (container.ContainerID == id)
                                    {
                                        objectContainer.InActive = true;
                                        db.SaveChanges();
                                        toReturn.Message = "Delete Restricted But Container Set to Inactive";
                                        return(toReturn);
                                    }
                                }
                            }
                        }
                        db.Containers.Remove(objectContainer);
                        db.SaveChanges();
                        toReturn.Message = "Delete Successful";
                    }
                    else
                    {
                        objectContainer.InActive = true;
                        db.SaveChanges();
                        toReturn.Message = "Delete Restricted But Container Set to Inactive";
                        return(toReturn);
                    }
                }
            }
            catch
            {
                toReturn.Message = "Delete Unsuccesful";
            }

            return(toReturn);
        }