public ActionResult UpdateTemplate(EmailTempletViewModels email) { string err = ""; Guid outId = Guid.Empty; if (!assessUtils.AddUpdateEmailTemplate(email, out outId, out err)) { return Json(new { isErr = true, errMsg = err }); } return Json(new { isErr = false, id = outId }); }
public bool AddUpdateEmailTemplate(EmailTempletViewModels model, out Guid TID, out string ErrMsg) { if (model == null) throw new ArgumentNullException("model"); try { ErrMsg = null; TID = Guid.NewGuid(); using (var ctx = new EvaluationSysEntities()) { if (model.TID == Guid.Empty) { ctx.EmailTemplate.Add(new EmailTemplate { Id = TID, EmailHead = model.EmailHead, EmailContent = model.EmailTemplet, CreateTime = DateTime.Now }); } else { var query = ctx.EmailTemplate.FirstOrDefault(f => f.Id == model.TID); if (query == null) throw new Exception("不正确的模板ID"); query.EmailHead = model.EmailHead ?? ""; query.EmailContent = model.EmailTemplet ?? ""; query.CreateTime = DateTime.Now; } return ctx.SaveChanges() >= 0; } } catch (Exception ex) { TID = Guid.Empty; ErrMsg = ex.GetBaseException().Message; return false; } }