//private Context db2 = new Context(); public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpContextBase objContext = controllerContext.HttpContext; QuotationCreateViewModel obj = new QuotationCreateViewModel(); obj.quotation.Annotation = objContext.Request.Form["QuotationInfo"]; return(obj); }
public ActionResult CreateAndAddProducts([ModelBinder(typeof(QuotationBinderCreate))] QuotationCreateViewModel qcvm, string[] DeliveryID) { if (ModelState.IsValid) { //aanmaken van quotation / customerdeliveryaddress en customer Quotation quotation = new Quotation(); CustomerDeliveryAddress cda = new CustomerDeliveryAddress(); Customer cus = new Customer(); //ophalen van customerDeliveryAddressID vanuit de array // eventueel nog test inbouwen voor lengte van array (check dat ze niet meer als 1 veld selecteren) int DeliveryId = 1; if (DeliveryID.Length == 1) { DeliveryId = Int32.Parse(DeliveryID.First()); } else { return(RedirectToAction("Create")); } // ophalen delivery info en van daaruit customer info cda = db.CustomerDeliveryAddresses.Find(DeliveryId); cus = db.Customers.Find(cda.CustomerId); // invullen van de klant info in de quotation DefaultQuotationInfo(quotation); quotation.FirstName = cus.FirstName; quotation.LastName = cus.LastName; quotation.Box = cus.Address.Box; quotation.CellPhone = cus.CellPhone; quotation.CustomerId = cus.CustomerId; quotation.Email = cus.Email; quotation.PostalCodeNumber = cus.Address.PostalCodeNumber; quotation.StreetName = cus.Address.StreetName; quotation.StreetNumber = cus.Address.StreetNumber; quotation.Town = cus.Address.Town; quotation.Annotation = qcvm.quotation.Annotation; quotation.customerDeliveryAddress = db.CustomerDeliveryAddresses.Find(DeliveryId); //toevoegen en saven db.Quotations.Add(quotation); db.SaveChanges(); int id = quotation.QuotationId; TempData["id"] = id; return(RedirectToAction("AddProducts")); } return(View(qcvm)); }
// GET: Quotations/Create public ActionResult Create(string sortOrder, string searchStringName, string searchStringTown, string currentFilterName, string currentFilterTown, int?page) { // quotation viewmodel + ipaged list users aanmaken + nieuwe quotation voor default stuff QuotationCreateViewModel qcvm = new QuotationCreateViewModel(); var customerList = from a in db.Customers select a; Quotation quotation = new Quotation(); DefaultQuotationInfo(quotation); qcvm.quotation = quotation; //zoeken / sorteren / paging //sorteren default op "name_desc" ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.TownSortParm = sortOrder == "town" ? "town_desc" : "town"; // als zoeken leeg is pagina 1 anders if (searchStringTown != null || searchStringName != null) { page = 1; } else { searchStringName = currentFilterName; searchStringTown = currentFilterTown; } ViewBag.CurrentFilterName = searchStringName; ViewBag.CurrentFilterTown = searchStringTown; // zoekvelden toepassen op klantenlijst //zoeken op naam (voor of achter en/of gemeente) if (!String.IsNullOrEmpty(searchStringTown)) { customerList = customerList.Where(s => s.Address.Town.ToUpper().Contains(searchStringTown.ToUpper())); } // zoeken op postalcode if (!String.IsNullOrEmpty(searchStringName)) { customerList = customerList.Where(s => s.LastName.ToUpper().Contains(searchStringName.ToUpper()) || s.FirstName.ToUpper().Contains(searchStringName.ToUpper())); } switch (sortOrder) { case "name_desc": customerList = customerList.OrderByDescending(s => s.LastName); break; case "town": customerList = customerList.OrderBy(s => s.Address.Town); break; case "town_desc": customerList = customerList.OrderByDescending(s => s.Address.Town); break; default: customerList = customerList.OrderBy(s => s.LastName); break; } var userDefinedInfo = db.UserDefinedSettings.Find(1); int pageSize = userDefinedInfo.DetailsResultLength; int pageNumber = (page ?? 1); qcvm.customers = customerList.ToPagedList(pageNumber, pageSize); return(View(qcvm)); }