public ActionResult Create(AspnetUsers user, string[] selectedObjects, bool isAdministrator) { // Note checkboxes require special handling in mvc // Posts Render an additional <input type="hidden".../> for checkboxes if checked which provides a true and false value. // This addresses scenarios where unchecked checkboxes are not sent in the request. // Sending a hidden input makes it possible to know that the checkbox // was present on the page when the request was submitted. // as a result of this querying formas parameters produces unexpected results. The workaround institued for // this problem takes account that only checkboxes which are selected/changed in selected Objects as passed. // Inspect the key value to work out what has changed. try { IUnitOfWorkFactory factory = new WebSiteUnitOfWorkFactory(); IAspNetUnitOfWork unitOfWork = factory.GetAspNetUnitOfWork(); List<CheckBoxListInfo> checkBoxListItems = GetCheckedBoxes(selectedObjects); ViewData["listItems"] = checkBoxListItems; user = unitOfWork.Save(user, isAdministrator, selectedObjects); return RedirectToAction("Index"); } catch (RuleException ex) { ex.CopyToModelState(ModelState); return View(); } catch (Exception ex) { RuleException rex = new RuleException("error", ex.Message); rex.CopyToModelState(ModelState); return View(); } }
/// <summary> /// Indexes the specified web site id. /// </summary> /// <param name="webSiteId">The web site id.</param> /// <returns>The view instance.</returns> public ActionResult Index(long? webSiteId) { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IWebSiteUnitOfWork webSitesUnitOfWork = factory.GetWebSiteUnitOfWork(); List<WebSite> webSites = webSitesUnitOfWork.List; webSiteId = (webSiteId.HasValue == true) ? webSiteId : webSites[0].Id; ViewData["webSites"] = this.CopyToSelectList(webSiteId.Value, webSites); IAspNetUnitOfWork aspNetUserUnitOfWork = factory.GetAspNetUnitOfWork(); List<AspnetUsers> users = aspNetUserUnitOfWork.ListByWebSiteId(webSiteId.Value); return View(users); }
public ActionResult Edit( string userId, string submitButton, AspnetUsers user, bool isAdministrator, string[] selectedObjects, FormCollection collection) { try { // Note checkboxes require special handling in mvc // Posts Render an additional <input type="hidden".../> for checkboxes if checked which provides a true and false value. // This addresses scenarios where unchecked checkboxes are not sent in the request. // Sending a hidden input makes it possible to know that the checkbox // was present on the page when the request was submitted. // as a result of this querying formas parameters produces unexpected results. The workaround institued for // this problem takes account that only checkboxes which are selected/changed in selected Objects as passed. // Inspect the key value to work out what has changed. IUnitOfWorkFactory factory = new WebSiteUnitOfWorkFactory(); IAspNetUnitOfWork unitOfWork = factory.GetAspNetUnitOfWork(); switch (submitButton) { case "Save": ViewData["userWebSites"] = GetUserWebSitesWithDefaultDetails(); user = unitOfWork.Save(user, isAdministrator, selectedObjects); return RedirectToAction("Index"); case "Delete": unitOfWork.Delete(user); return RedirectToAction("Index"); default: // If they've submitted the form without a submitButton, // just return the view again. return RedirectToAction("View"); } } catch (Exception ex) { RuleException rex = new RuleException("error", ex.Message); rex.CopyToModelState(ModelState); return View(); } }
/// <summary> /// Edits the specified id. /// </summary> /// <param name="id">The identification value.</param> /// <returns>The view instance.</returns> public ActionResult Edit(string id) { IUnitOfWorkFactory factory = new WebSiteUnitOfWorkFactory(); IAspNetUnitOfWork unitOfWork = factory.GetAspNetUnitOfWork(); AspnetUsers user = unitOfWork.GetById(id); ViewData["isAdministrator"] = Roles.IsUserInRole(user.Username, "Admin"); List<UserWebSite> userWebSites = GetUserWebSitesWithDefaultDetails(); List<CheckBoxListInfo> checkBoxListItems = new List<CheckBoxListInfo>(); foreach (UserWebSite userWebSite in userWebSites) { bool isChecked = false; if (user.WebSites.Find(q => q.Id == userWebSite.WebSiteId) != null) { isChecked = true; } CheckBoxListInfo info = new CheckBoxListInfo(userWebSite.WebSiteId.ToString(), userWebSite.SiteName, isChecked); checkBoxListItems.Add(info); } ViewData["listItems"] = checkBoxListItems; return View(user); }