public ActionResult AssessSave(AssessViewModels model)
 {
     DateTime time = DateTime.Now;
     if (!questionnaireUtils.CheckExpireTime(model.UserId, out time))
     {
         throw new LinkExpiredException(time);
     }
     string err = "";
     var dic = assessUtils.GetTypedefs("freq");
     if (!dic.ContainsKey(model.Frequency))
     {
         return JavaScript("alert('请输入正确的频率')");
     }
     model.Frequency = assessUtils.GetTypedefs("freq")[model.Frequency];
     if (!assessUtils.UpdateAssessAttr(model, new string[1] { "Frequency" }, out err))
     {
         Response.Write(string.Format(jsFormat, HttpUtility.JavaScriptStringEncode(err)));
         return new EmptyResult();
     }
     var key = assessUtils.GetTopicArr(model.AssessId.Value, model.UserId);
     if (!string.IsNullOrEmpty(key))
     {
         ViewBag.TotalCount = key.Split(',').Length;
     }
     var config = configUtils.GetSettingModel();
     ViewBag.AssessPeriod = config.AssessPeriod;
     ViewBag.PaperTimeSpandMinute = config.PaperTimeSpandMinute;
     return PartialView("Illustration", model);
 }
 public AssessUtils()
 {
     defaultModel = new AssessViewModels
     {
         IsUserId = Guid.Empty,
         UserId = Guid.Empty,
         IsUserName = "",
         UserName = "",
         PaperId = 0,
         PaperName = "",
         RecordNum = 0,
         RelationList = new string[0]
     };
     emailUtils = new EmailUtils();
 }
 public ActionResult AssessSave(AssessViewModels assess)
 {
     string err = ""; int assessid = 0;
     if (!assessUtils.AddUpdateAssess(assess, out assessid, out err))
     {
         return Json(new { isErr = true, errMsg = HttpUtility.JavaScriptStringEncode(err) });
     }
     else return Json(new { isErr = false, aid = assessid });
 }
 public bool UpdateAssessAttr(AssessViewModels model, IEnumerable<string> PropertyNames, out string ErrMsg)
 {
     ErrMsg = null;
     try
     {
         using(var ctx = new EvaluationSysEntities())
         {
             var query = (from c in ctx.AssessObj where c.Id == model.AssessId select c).FirstOrDefault();
             if(query == null)
             {
                 ErrMsg = "不正确的参数";
                 return false;
             }
             foreach(string name in PropertyNames)
             {
                 var p = typeof(AssessViewModels).GetProperty(name);
                 if (p == null) continue;
                 var pi = typeof(AssessObj).GetProperty(name);
                 if (pi != null)
                     pi.SetValue(query, p.GetValue(model).ConvertObject(pi.PropertyType));
             }
             return ctx.SaveChanges() >= 0;
         }
     }
     catch (Exception ex)
     {
         ErrMsg = ex.GetBaseException().Message;
         return false;
     }
 }
 public bool AddUpdateAssess(AssessViewModels model, out int AssessId, out string ErrMsg)
 {
     ErrMsg = null; AssessId = model.AssessId ?? 0;
     try
     {
         AssessObj obj = null;
         DateTime deadline = DateTime.Parse("1900-1-1");
         using (var ctx = new EvaluationSysEntities())
         {
             var setting = (from c in ctx.SettingConfig where c.Name == "DeadLine" select c.Value).FirstOrDefault();
             var userinfo = ctx.UserInfo.FirstOrDefault(f => f.Id == model.UserId && f.PID == ProjectId);
             if (userinfo == null) throw new Exception("不正确的用户ID");
             DateTime.TryParse(setting, out deadline);
             if (!model.AssessId.HasValue)
             {
                 obj = new AssessObj
                 {
                     IsUserID = model.IsUserId,
                     UserID = model.UserId,
                     SysEndTime = deadline,
                     Bind = model.Relation,
                     TestPageID = model.PaperId,
                     Status = -1,
                     PID = ProjectId,
                     LastName = userinfo.LastName,
                     FirstName = userinfo.FirstName,
                     Frequency = "",
                     BindPageSave = ""
                 };
                 ctx.AssessObj.Add(obj);
             }
             else
             {
                 var update = (from c in ctx.AssessObj
                               where c.Id == model.AssessId && c.PID == ProjectId
                               select c).FirstOrDefault();
                 if (update != null)
                 {
                     update.IsUserID = model.IsUserId;
                     update.UserID = model.UserId;
                     update.Bind = model.Relation;
                     update.SysEndTime = deadline;
                     update.TestPageID = model.PaperId;
                 }
             }
             int ret = ctx.SaveChanges();
             if (!model.AssessId.HasValue) AssessId = obj.Id;
             return ret >= 0;
         }
     }
     catch (Exception ex)
     {
         ErrMsg = ex.GetBaseException().Message;
         return false;
     }
 }