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> /// Sends the emails. /// </summary> /// <returns></returns> public ActionResult SendEmails() { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IMailUnitOfWork mailUnitOfWork = factory.GetMailUnitOfWork(); mailUnitOfWork.SendEmails("", "", ""); 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 Index(int? id) { SelectList hoursList = null; SelectList minutesList = null; if (id.HasValue) { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IMailUnitOfWork mailUnitOfWork = factory.GetMailUnitOfWork(); Mail mail = mailUnitOfWork.GetById(id.Value); ViewData["mail"] = mail; IScheduleUnitOfWork scheduleUnitOfWork = factory.GetScheduleUnitOfWork(); Schedule schedule = scheduleUnitOfWork.GetByMailId(mail.Id); ViewData["schedule"] = schedule; if (schedule.StartDateTime != null) { hoursList = this.CopyToSelectList("/App_Data/Hours.xml", schedule.StartDateTime.Value.Hour); minutesList = this.CopyToSelectList("/App_Data/Minutes.xml", schedule.StartDateTime.Value.Minute); } else { hoursList = this.CopyToSelectList("/App_Data/Hours.xml", 0); minutesList = this.CopyToSelectList("/App_Data/Minutes.xml", 0); } } else { hoursList = this.CopyToSelectList("/App_Data/Hours.xml", 0); minutesList = this.CopyToSelectList("/App_Data/Minutes.xml",0); } ViewData["hoursList"] = hoursList; ViewData["minutesList"] = minutesList; return View(); }
/// <summary> /// Gets the web sites. /// </summary> /// <returns>List of Web sites.</returns> private static List<WebSite> GetWebSites() { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IWebSiteUnitOfWork webSitesUnitOfWork = factory.GetWebSiteUnitOfWork(); return webSitesUnitOfWork.List; }
/// <summary> /// Gets the user web sites for create. /// </summary> /// <returns>List of Use Web sites with UserSubscribedToWebSite == false.</returns> private static List<UserWebSite> GetUserWebSitesWithDefaultDetails() { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IWebSiteUnitOfWork webSitesUnitOfWork = factory.GetWebSiteUnitOfWork(); List<WebSite> webSites = webSitesUnitOfWork.List; List<UserWebSite> userWebSites = new List<UserWebSite>(); Action<WebSite> action = new Action<WebSite>(q => userWebSites.Add(new UserWebSite { SiteName = q.SiteName, UserSubscribedToWebSite = false, WebSiteId = q.Id })); webSites.ForEach(action); return userWebSites; }
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); }
public ActionResult Index(long? Id, string submitButton, Schedule schedule, FormCollection collection) { try { SelectList hoursList = this.CopyToSelectList("/App_Data/Hours.xml",0); SelectList minutesList = this.CopyToSelectList("/App_Data/Minutes.xml",0); ViewData["hoursList"] = hoursList; ViewData["minutesList"] = minutesList; switch (submitButton) { case "Save": // delegate sending to another controller action schedule.DaysOfWeekToRun = collection["DaysOfWeekToRun"]; schedule.Enabled = true; schedule.CreatedBy = User.Identity.Name; IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IScheduleUnitOfWork scheduleUnitOfWork = factory.GetScheduleUnitOfWork(); if (schedule.StartDateTime != null) schedule.StartDateTime = new DateTime(schedule.StartDateTime.Value.Year, schedule.StartDateTime.Value.Month, schedule.StartDateTime.Value.Day, Convert.ToInt32(collection["hoursList"]), Convert.ToInt32(collection["minutesList"]), 0); if (schedule.EndDateTime != null) schedule.EndDateTime = new DateTime(schedule.EndDateTime.Value.Year, schedule.EndDateTime.Value.Month, schedule.EndDateTime.Value.Day, Convert.ToInt32(collection["hoursList"]), Convert.ToInt32(collection["minutesList"]), 0); if (Id.HasValue) { schedule.MailId = (long)Id; schedule.Id = scheduleUnitOfWork.GetByMailId(schedule.MailId).Id; } scheduleUnitOfWork.Save(schedule); return RedirectToAction("Index", "WebSiteEMails"); } return View("Index", schedule); } catch (RuleException ex) { ex.CopyToModelState(ModelState); return View(); } catch (Exception ex) { RuleException rex = new RuleException("error", ex.Message); rex.CopyToModelState(ModelState); return View(); } }
/// <summary> /// Edits the mail. /// </summary> /// <param name="id">The identification value.</param> /// <returns>The view instance.</returns> public ActionResult EditMail(long? id) { IUnitOfWorkFactory factory = new ScheduMail.UnitsOfWork.WebSiteUnitOfWorkFactory(); IMailUnitOfWork unitOfWork = factory.GetMailUnitOfWork(); Mail mail = id.HasValue ? unitOfWork.GetById(id.Value) : new Mail(); return View(mail); }