// 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)); }
// GET: Orders/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTmp.Where(odt => odt.UserName == User.Identity.Name).ToList(), }; return(View(view)); }
public ActionResult Create(Orders orders) { if (ModelState.IsValid) { db.Orders.Add(orders); db.SaveChanges(); return(RedirectToAction("Index")); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName"); return(View(orders)); }
public ActionResult Edit(Orders orders) { if (ModelState.IsValid) { db.Entry(orders).State = EntityState.Modified; var responseSaveImg = DBHelper.SaveChanges(db); if (responseSaveImg.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, responseSaveImg.Message); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName", orders.CustomerId); return(View(orders)); }
// GET: Orders/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Orders orders = db.Orders.Find(id); if (orders == null) { return(HttpNotFound()); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName", orders.CustomerId); return(View(orders)); }
public ActionResult Create(NewOrderView view) { if (ModelState.IsValid) { var response = MovementsHelper.NewOrder(view, User.Identity.Name); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName", view.CustomerId); view.Details = db.OrderDetailTmp.Where(odt => odt.UserName == User.Identity.Name).ToList(); return(View(view)); }