public ActionResult ScheduleSetting(EEmailScheduleSetting emailschedulesetting) { int OK = 1; if (ModelState.IsValid) { string strErr = ""; if (OK > 0) { OK = 0; if (emailschedulesetting.Id < 1) { if (UpdateSQLJob(emailschedulesetting.Period, emailschedulesetting.Active, emailschedulesetting.Frequency, ref strErr)) { db.EmailScheduleSetting.Add(emailschedulesetting); OK = 1; } } else { if (UpdateSQLJob(emailschedulesetting.Period, emailschedulesetting.Active, emailschedulesetting.Frequency, ref strErr)) { db.Entry(emailschedulesetting).State = EntityState.Modified; OK = 1; } } } if (OK == 1) { db.SaveChanges(); ViewBag.ScheduleTaskResult = "(儲存成功)"; } else if(OK == 0) { ViewBag.ScheduleTaskResult = String.Format("(儲存失敗:{0})", strErr); } return View("Index",GetIndexModel()); } else { ModelState.AddModelError("", "請輸入任一條件值!!"); } return RedirectToAction("Index"); }
public static int GetPageSize(EmailSrvEntities db) { int nPageSize = 10; var pagesize = db.EmailScheduleSetting.Where(ess => ess.Name == "PageSize"); if (pagesize == null || pagesize.Count() < 1) { EEmailScheduleSetting ess = new EEmailScheduleSetting(); ess.Name = "PageSize"; ess.Value = "10"; ess.Period = 1; db.EmailScheduleSetting.Add(ess); db.SaveChanges(); } else { bool bOK = false; foreach(var ess in pagesize) { if (bOK) { db.EmailScheduleSetting.Remove(ess); } else { try { nPageSize = Convert.ToInt32(ess.Value); bOK = true; } catch { db.EmailScheduleSetting.Remove(ess); } } } if (!bOK) { EEmailScheduleSetting ess = new EEmailScheduleSetting(); ess.Name = "PageSize"; ess.Value = "10"; ess.Period = 1; db.EmailScheduleSetting.Add(ess); } db.SaveChanges(); } return nPageSize; }
public ActionResult _PartialTemplateVariable(TemplateVariables templatevariables) { var agentVar = db.EmailScheduleSetting.Where(s => s.Name == "AgentID").FirstOrDefault(); if (agentVar == null) { var emailsetting = new EEmailScheduleSetting(); emailsetting.Name = "AgentID"; emailsetting.Value = templatevariables.AgentID; emailsetting.Period = 1; db.EmailScheduleSetting.Add(emailsetting); } else { agentVar.Value = templatevariables.AgentID; agentVar.Period = 1; db.Entry(agentVar).State = EntityState.Modified; } db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult _AjaxUpdateExpireLen(string expirelen) { try { var emailschedulesetting = db.EmailScheduleSetting.Where(s => s.Name == "ExpireLen").FirstOrDefault(); if (emailschedulesetting == null) { emailschedulesetting = new EEmailScheduleSetting(); emailschedulesetting.Name = "ExpireLen"; emailschedulesetting.Value = expirelen; emailschedulesetting.Period = 1; db.EmailScheduleSetting.Add(emailschedulesetting); } else { emailschedulesetting.Value = expirelen; emailschedulesetting.Period = 1; db.Entry(emailschedulesetting).State = EntityState.Modified; } db.SaveChanges(); var ret = new { result = 1, err = "" }; return Json(ret, JsonRequestBehavior.AllowGet); } catch (Exception ex) { var ret = new { result = 0, err = ex.Message }; return Json(ret, JsonRequestBehavior.AllowGet); } }