Esempio n. 1
0
        //
        // GET: /GM_POC/
        public ActionResult CreatePOC()
        {
            CreateEditPOCViewModel VM = new CreateEditPOCViewModel();
            VM.Products = db.Product.ToList<Product>();
            VM.Incoterms = db.Incoterm.ToList<Incoterm>();

            return View(VM);
        }
Esempio n. 2
0
        public ActionResult CreatePOC(CreateEditPOCViewModel VM, string submitButton)
        {
            //Agregar objeto de destination y de port directamente con AJAX en los typeahead
            if (VM.Alerts == null)
                VM.Alerts = new List<AlertItem>();

            else if(VM.Alerts.Count != 0)
            {
                VM.Alerts.Clear();
            }

            int status = 0;

            switch (submitButton)
            {
                case "Save":
                    status = 1;
                    validateCreatePost(VM, false);
                    break;
                case "Save and Send":
                    status = 2;
                    validateCreatePost(VM, true);
                    break;
            }

            if (VM.Alerts.Count > 0)
            {
                VM.Products = db.Product.ToList<Product>();
                VM.Incoterms = db.Incoterm.ToList<Incoterm>();
                return View(VM);
            }

            POC POC = new POC();
            POC = VM.POC;

            POC.Status = status;

            POC.CreationDate = DateTime.Today;

            Schedule schedule = new Schedule();

            db.POC.Add(POC);

            schedule.POC = POC;

            db.Schedule.Add(schedule);

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                VM.Alerts.Add(new AlertItem("Unexpected database error. Changes could not be saved."));
            }

            return RedirectToAction("Inbox", new {controller = "GM_Inbox" });
        }
Esempio n. 3
0
        public void validateCreatePost(CreateEditPOCViewModel VM, bool postType)
        {
            if (VM.POC == null)
                VM.Alerts.Add(new AlertItem("Unexpected error while sending data to server."));

            List<Customer> customers = db.Customer.ToList<Customer>();
            Customer finalCustomer = new Customer();

            if (VM.CustomerProperty != null)
            {
                string queryLower = VM.CustomerProperty.ToLower();

                foreach (Customer c in customers)
                {
                    bool cond = (c.CustomerProperty).ToLower().Equals(queryLower);
                    if (cond)
                    {
                        finalCustomer = c;
                    }
                }
            }

            if (finalCustomer.Name != null)
            {
                VM.POC.Customer = finalCustomer;
            }

            else
            {
                VM.Alerts.Add(new AlertItem("Selected Customer is not valid."));
            }

            if (VM.SelectedIncotermId > 0)
            {
                VM.POC.CustomerIncoterm = db.Incoterm.Find(VM.SelectedIncotermId);
            }
            else if(postType)
            {
                VM.Alerts.Add(new AlertItem("Selected Incoterm is not valid."));
            }
            if (VM.SelectedProductId > 0)
            {
                VM.POC.Product = db.Product.Find(VM.SelectedProductId);
            }
            else if (postType)
            {
                VM.Alerts.Add(new AlertItem("Selected Product Type is not valid."));
            }

            if (VM.POC.AmountTotal <= 0)
            {
                if (postType)
                {
                    VM.Alerts.Add(new AlertItem("Amount must be a positive number."));
                }

                else
                    VM.POC.AmountTotal = 0;
            }

            if (VM.POC.PricePerTon <= 0)
            {
                if (postType)
                {
                    VM.Alerts.Add(new AlertItem("Price Per Ton must be a positive number."));
                }
                else
                    VM.POC.PricePerTon = 0;
            }
        }
Esempio n. 4
0
 public void reloadEditPOC(CreateEditPOCViewModel VM)
 {
     VM.Products = db.Product.ToList<Product>();
     VM.Incoterms = db.Incoterm.ToList<Incoterm>();
 }
Esempio n. 5
0
        public ActionResult EditPOC(CreateEditPOCViewModel VM, string submitButton, int id)
        {
            POC POC = db.POC.Find(id);

            if (VM.Alerts == null)
                VM.Alerts = new List<AlertItem>();

            else if (VM.Alerts.Count != 0)
            {
                VM.Alerts.Clear();
            }

            int status = 0;

            switch (submitButton)
            {
                case "Save":
                    status = 1;
                    validateCreatePost(VM, false);
                    break;
                case "Save and Send":
                    status = 2;
                    validateCreatePost(VM, true);
                    break;
            }

            if (VM.Alerts.Count > 0)
            {
                reloadEditPOC(VM);
                return View(VM);
            }

            POC.AmountTotal = VM.POC.AmountTotal;
            POC.Comments = VM.POC.Comments;
            POC.PricePerTon = VM.POC.PricePerTon;

            POC.Customer = VM.POC.Customer;
            POC.CustomerIncoterm = VM.POC.CustomerIncoterm;

            POC.Product = VM.POC.Product;

            POC.Status = status;

            db.Entry(POC).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                VM.Alerts.Add(new AlertItem("Unexpected database error. Changes could not be saved."));
            }

            return RedirectToAction("Inbox", new { controller = "GM_Inbox" });
        }
Esempio n. 6
0
        public ActionResult EditPOC(int id = 0)
        {
            var purchaseordercustomerFull = db.POC.Include(x => x.Product).Include(x => x.Customer);
            var result = purchaseordercustomerFull.Where(p => p.POCID == id);
            List<POC> purchaseordercustomerList = result.ToList<POC>();

            if (purchaseordercustomerList.Count == 0)
            {
                return HttpNotFound();
            }

            POC POC = purchaseordercustomerList[0];
            CreateEditPOCViewModel VM = new CreateEditPOCViewModel();

            VM.Products = db.Product.ToList<Product>();
            VM.Incoterms = db.Incoterm.ToList<Incoterm>();

            VM.POC = POC;

            if(POC.CustomerIncoterm != null)
                VM.SelectedIncotermId = POC.CustomerIncoterm.IncotermID;
            if(POC.Product != null)
                VM.SelectedProductId = POC.Product.ProductID;

            if (POC.Customer != null)
            {
                VM.CustomerProperty = POC.Customer.CustomerProperty;
            }

            return View(VM);
        }