public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpContextBase objContext = controllerContext.HttpContext; CustomerAddDeliveryAddressViewModel obj = new CustomerAddDeliveryAddressViewModel(); obj.address = new Address(); obj.deliveryAddress = new CustomerDeliveryAddress(); obj.deliveryAddress.DeliveryAddressInfo = objContext.Request.Form["DeliveryAddressInfo"]; obj.deliveryAddress.Box = Int32.Parse(objContext.Request.Form["Box"]); obj.deliveryAddress.PostalCodeNumber = Int32.Parse(objContext.Request.Form["PostalCodeNumber"]); obj.deliveryAddress.StreetName = objContext.Request.Form["StreetName"]; obj.deliveryAddress.StreetNumber = Int32.Parse(objContext.Request.Form["StreetNumber"]); obj.deliveryAddress.Town = objContext.Request.Form["Town"]; obj.deliveryAddress.CustomerId = Int32.Parse(objContext.Request.Form["CustomerId"]); return obj; }
// GET: Customers/AddDeliveryAddress/5 public ActionResult AddDeliveryAddress(int? id, int? page, string sortOrder, string searchStringTown, string searchStringPostal, string currentFilterTown, string currentFilterPostal, string returnUrl) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (returnUrl == null) { ViewBag.returnUrl = Request.UrlReferrer; } else { ViewBag.returnUrl = returnUrl; } ViewBag.CurrentSort = sortOrder; // hij kijkt of town en postal leeg is indien niet leeg terug reset naar pagina 1 if (searchStringTown != null || searchStringPostal != null) { page = 1; } else { searchStringTown = currentFilterTown; searchStringPostal = currentFilterPostal; } ViewBag.CurrentFilterTown = searchStringTown; ViewBag.CurrentFilterPostal = searchStringPostal; //lijst vullen met adressen om weer te geven var addressList = from a in db.Addresses select a; // zoekvelden toepassen op addresslist //zoeken op gemeente of adres if (!String.IsNullOrEmpty(searchStringTown)) { addressList = addressList.Where(s => s.Town.ToUpper().Contains(searchStringTown.ToUpper()) || s.StreetName.ToUpper().Contains(searchStringTown.ToUpper())); } // zoeken op postalcode if (!String.IsNullOrEmpty(searchStringPostal)) { int postalCode = int.Parse(searchStringPostal); addressList = addressList.Where(s => s.PostalCodeNumber == (postalCode)) ; } //sorting parameters ViewBag.TownSortParm = String.IsNullOrEmpty(sortOrder) ? "town_desc" : ""; ViewBag.PostalCodeSortParm = String.IsNullOrEmpty(sortOrder) ? "postal_desc" : "postal"; switch (sortOrder) { case "town_desc": addressList = addressList.OrderByDescending(s => s.Town); break; case "postal": addressList = addressList.OrderBy(s => s.PostalCodeNumber); break; case "postal_desc": addressList = addressList.OrderByDescending(s => s.PostalCodeNumber); break; default: addressList = addressList.OrderBy(s => s.Town); break; } //gesorteerde info in viewbag + paged var userDefinedInfo = db.UserDefinedSettings.Find(1); int pageSize = userDefinedInfo.DetailsResultLength; int pageNumber = (page ?? 1); ViewBag.Addressess = addressList.ToPagedList(pageNumber, pageSize); Customer customer = db.Customers.Find(id); CustomerAddDeliveryAddressViewModel cavm = new CustomerAddDeliveryAddressViewModel(); cavm.customer = customer; if (customer == null) { return HttpNotFound(); } return View("AddDeliveryAddress",cavm); }