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(); }
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(); } }