public UserUtils()
 {
     defaultModel = new UserViewModels
     {
         UserId = Guid.Empty,
         EmailAddr = "",
         Department = "",
         Position = "",
         UserName = "",
         UserNo = ""
     };
 }
 public ActionResult UserSave(UserViewModels user)
 {
     string err = ""; Guid uid;
     if (!userUtils.AddUpdateUserInfo(user, out uid, out err))
     {
         return Json(new { isErr = true, errMsg = err });
     }
     else return Json(new { uid = uid, isErr = false });
 }
 public bool AddUpdateUserInfo(UserViewModels model, out Guid UserId, out string ErrMsg)
 {
     ErrMsg = null;
     UserId = Guid.NewGuid();
     try
     {
         if(CheckUserNoRepeat(model.UserNo))
         {
             ErrMsg = "项目内用户编号不可重复";
             return false;
         }
         using (var ctx = new EvaluationSysEntities())
         {
             if (model.UserId == default(Guid))
             {
                 ctx.UserInfo.Add(new UserInfo
                 {
                     Id = UserId,
                     BM = model.Department,
                     ZW = model.Position,
                     Email = model.EmailAddr,
                     UserName = model.UserName,
                     UserNum = model.UserNo,
                     PID = ProjectId,
                     OperatrTime = DateTime.Now,
                 });
             }
             else
             {
                 UserId = model.UserId;
                 var user = (from c in ctx.UserInfo
                             where c.Id == model.UserId
                             && c.PID == ProjectId
                             && c.ProjectMng.Status >= 0
                             select c).FirstOrDefault();
                 if (user != null)
                 {
                     user.UserName = model.UserName ?? "";
                     user.UserNum = model.UserNo ?? "";
                     user.Email = model.EmailAddr;
                     user.BM = model.Department ?? "";
                     user.ZW = model.Position ?? "";
                     user.OperatrTime = DateTime.Now;
                 }
             }
             return ctx.SaveChanges() >= 0;
         }
     }
     catch (Exception ex)
     {
         ErrMsg = ex.GetBaseException().Message;
         return false;
     }
 }