public ActionResult Create(VendorItem vendoritem)
        {
            if (ModelState.IsValid)
            {
                db.VendorItems.Add(vendoritem);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(vendoritem);
        }
        //
        // GET: /Inventory/OpenPurchaseOrderbyItemTab
        public ActionResult CreateVendorTab(string id)
        {
            int nYear = 0;
            int nMonth = 0;
            int nDay = 0;
            string szMsg = "";
            DateTime dDate = DateTime.Now;

            List<KeyValuePair<string, string>> listSelector = new List<KeyValuePair<string, string>>();

            //Get theActive/Inactive list
            listSelector = new List<KeyValuePair<string, string>>();
            listSelector.Add(new KeyValuePair<string, string>("Y", "Active"));
            listSelector.Add(new KeyValuePair<string, string>("N", "Inactive"));
            SelectList activeinactivelist = new SelectList(listSelector, "Key", "Value");
            ViewBag.ActiveInactivelist = activeinactivelist;

            ITEM item = null;
            item = db.ITEMs.Find(id);

            IQueryable<VendorItem> qryvendoritem = null;
            VendorItem vendoritem = null;

            List<VendorItem> vendoritemList = new List<VendorItem>();
            listSelector = new List<KeyValuePair<string, string>>();
            //qryvendoritem = db.VendorItems.Where(cutadd => cutadd.ItemId == item.ItemID).OrderBy(cutadd => cutadd.VendorNo);
            qryvendoritem = db.VendorItems.Where(cutadd => cutadd.ItemId == item.ItemID && cutadd.VendorNo != null).OrderBy(cutadd => cutadd.VendorNo);
            if (qryvendoritem.Count() > 0)
            {
                //custSalesContact = qryCusSal.FirstOrDefault<CustomersSalesContact>();
                foreach (var vendoritemHlp in qryvendoritem)
                {
                    vendoritemList.Add(vendoritemHlp);

                    var qryVendor = db.VendorsContactAddresses.Join(db.Vendors, vdca => vdca.VendorId, vd => vd.Id, (vdca, vd)
                        => new { vdca, vd }).Where(Nvdca => Nvdca.vd.VendorNo == vendoritemHlp.VendorNo).OrderBy(Nvdca => Nvdca.vdca.CompanyName);
                    if (qryVendor.Count() > 0)
                    {
                        foreach (var itemVendor in qryVendor)
                        {
                            szMsg = string.Format("{0} - {1} -({2})", itemVendor.vdca.CompanyName, itemVendor.vd.VendorNo, vendoritemHlp.Id.ToString());
                            listSelector.Add(new KeyValuePair<string, string>(itemVendor.vd.VendorNo, szMsg));
                            //listSelector.Add(new KeyValuePair<string, string>(vendoritemHlp.Id.ToString(), vendoritemHlp.VendorNo));
                            if (vendoritem == null)
                            {
                                vendoritem = vendoritemHlp;
                                ViewBag.VendorItemID = vendoritem.Id;
                            }
                        }
                    }

                }
            }
            else
            {
                //Get the first vendoritem for this item
                vendoritem = db.VendorItems.Where(vdit => vdit.ItemId == item.ItemID).FirstOrDefault<VendorItem>();
                if (vendoritem != null)
                {
                    vendoritemList.Add(vendoritem);
                    ViewBag.VendorItemID = vendoritem.Id;
                }
                else
                {
                    nYear = dDate.Year;
                    nMonth = dDate.Month;
                    nDay = dDate.Day;
                    dDate = new DateTime(nYear, nMonth, nDay, 0, 0, 0);
                    vendoritem = new VendorItem();
                    vendoritem.ItemId = item.ItemID;
                    //vendoritem.LeadTime = dDate;
                    db.VendorItems.Add(vendoritem);
                    db.SaveChanges();
                    vendoritemList.Add(vendoritem);
                    ViewBag.VendorItemID = vendoritem.Id;
                }
            }
            SelectList vendorItemlist = new SelectList(listSelector, "Key", "Value");
            ViewBag.VendorItemList = vendorItemlist;
            ViewBag.VendorItemListHas = listSelector.Count;

            //Get the VendorNo select list
            listSelector = new List<KeyValuePair<string, string>>();
            var qryVendorHlp = db.VendorsContactAddresses.Join(db.Vendors, vdca => vdca.VendorId, vd => vd.Id, (vdca, vd)
                => new { vdca, vd }).OrderBy(Nvdca => Nvdca.vdca.CompanyName);
            if (qryVendorHlp.Count() > 0)
            {
                foreach (var itemAllVendors in qryVendorHlp)
                {
                    szMsg = string.Format("{0} - {1}", itemAllVendors.vdca.CompanyName, itemAllVendors.vd.VendorNo);
                    listSelector.Add(new KeyValuePair<string, string>(itemAllVendors.vd.VendorNo, szMsg));
                }
            }
            SelectList vendornolist = new SelectList(listSelector, "Key", "Value");
            ViewBag.VendorNoList = vendornolist;

            return View(item);
        }
        public ActionResult CreateEditVendor01(VendorItem vendoritem, string itemid)
        {
            if (ModelState.IsValid)
            {
                vendoritem.UpdateDate = Convert.ToDateTime(DateTime.Now);
                db.Entry(vendoritem).State = EntityState.Modified;
                db.SaveChanges();
            }

            return RedirectToAction("Edit", new { id = itemid });
        }
        public ActionResult CreateEditVendor(VendorItem vendoritem, string leadtimeHlp, string VendorNoselectedid, string itemselectedid)
        {
            int nId = 0;
            int nYear = 0;
            int nMonth = 0;
            int nDay = 0;
            int nMinutes = 0;
            int nSeconds = 0;
            string szMsg = "";
            string szId = "";
            string[] szLeadTime = null;
            DateTime dDate = DateTime.Now;

            VendorsContactAddress vendoraddres = null;

            if (ModelState.IsValid)
            {
                if (vendoritem.Id == 0)
                {
                    db.VendorItems.Add(vendoritem);
                    vendoritem.ItemId = itemselectedid;
                    vendoritem.VendorNo = VendorNoselectedid;
                    vendoritem.UpdateDate = DateTime.Now;
                    vendoritem.LeadTimeHrs = 0;
                    vendoritem.LeadTimeMin = 0;
                    vendoritem.LeadTimeSec = 0;
                }
                else
                {
                    szId = Request.Form["venaddId"];

                    if (!string.IsNullOrEmpty(szId))
                    {
                        nId = Convert.ToInt32(szId);
                        vendoraddres = db.VendorsContactAddresses.Find(nId);
                        if (vendoraddres != null)
                        {
                            vendoraddres.CompanyName = Request.Form["CompanyName"];
                            vendoraddres.FirstName = Request.Form["FirstName"];
                            vendoraddres.LastName = Request.Form["LastName"];
                            vendoraddres.Tel1 = Request.Form["Tel1"].Replace("-", "");
                            vendoraddres.Tel2 = Request.Form["Tel2"].Replace("-", "");
                            vendoraddres.Tel = Request.Form["Tel3"].Replace("-", "");
                            vendoraddres.Fax = Request.Form["Fax"].Replace("-", "");
                            vendoraddres.Address = Request.Form["Addres1"];
                            vendoraddres.Note = Request.Form["Addres2"];
                            vendoraddres.Address3 = Request.Form["Addres3"];
                            vendoraddres.City = Request.Form["City"];
                            vendoraddres.State = Request.Form["State"];
                            vendoraddres.Zip = Request.Form["Zip"];
                            vendoraddres.Country = Request.Form["Country"];
                            vendoraddres.Email = Request.Form["Email"];
                            vendoraddres.Website = Request.Form["Website"];

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

                        }
                    }

                }
                db.SaveChanges();
                //return RedirectToAction("CreateVendorTab", new { id = vendoritem.ItemId });

                TempData["EditVendor"] = "EditVendor";
                return RedirectToAction("Edit", new { id = vendoritem.ItemId });
                //return RedirectToAction("Index");
            }

            return RedirectToAction("Index");
        }
 public ActionResult Edit(VendorItem vendoritem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vendoritem).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(vendoritem);
 }