// GET: OrderHeaders/Create public ActionResult Create(int?id) { var view = new NewOrderView { Date = DateTime.Now, NeedByDate = DateTime.Now }; ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName"); var v = db.NewOrderView.Where(o => o.UserId == 1).FirstOrDefault(); if (v != null) { ViewBag.CustomerId = new SelectList(db.Customers.Where(c => c.VendorId == 74 && c.CustomerId == v.CustomerId), "CustomerId", "Names"); ViewBag.ShipToId = new SelectList(db.ShipToes.Where(c => c.VendorId == 74), "ShipToId", "ShipToName", v.ShipToId); ViewBag.ContactId = new SelectList(db.Contacts.Where(c => c.VendorId == 74 && c.ShipToId == v.ShipToId), "ContactId", "Name", v.ContactId); ViewBag.PriceListId = new SelectList(CombosHelper.GetPriceList(v.CustomerId).OrderBy(P => P.PriceListId), "PriceListId", "ListDescription", v.PriceListId); view = v; } else { ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(74), "CustomerId", "Names"); ViewBag.ShipToId = new SelectList(CombosHelper.GetShipto(74), "ShipToId", "ShipToName"); ViewBag.ContactId = new SelectList(CombosHelper.GetContact(74), "ContactId", "Name"); ViewBag.PriceListId = new SelectList(db.PriceLists.OrderBy(P => P.PriceListId), "PriceListId", "ListDescription"); } view.OrderDetails = db.OrderDetailTmp.Where(o => o.UserId == 1).ToList(); //ViewBag.ShipToId = new SelectList(db.ShipToes.Where(c => c.VendorId == 74 && c.CustomerId == db.Customers.FirstOrDefault().CustomerId).OrderBy(c => c.ShipToName), "ShipToId", "ShipToName"); //ViewBag.ContactId = new SelectList(db.Contacts.Where(c => c.VendorId == 74 && c.ShipToId == db.ShipToes.FirstOrDefault().ShipToId).OrderBy(c => c.Name), "ContactId", "Name"); //ViewBag.PriceListId = new SelectList(db.PriceLists.Where(p => p.PriceListId == 0).OrderBy(P => P.PriceListId), "PriceListId", "ListDescription"); return(View(view)); }