public ActionResult Eval(UserEvalModel eval) { try { Task task = TaskRepository.Get(eval.TaskId); if (task == null) return JsonError("任务不存在"); User userFrom = UserRepository.Get(eval.FromUserId); if (userFrom == null) return JsonError("评价人不存在"); User userTo = UserRepository.Get(eval.ToUserId); if (userTo == null) return JsonError("被评价人不存在"); UserEval userEval = new UserEval(); userEval.Task = task; if (task.User.LoginName.Equals(userTo.LoginName)) { userEval.UserRole = UserRole.雇主; } else { userEval.UserRole = UserRole.雇员; } userEval.FromUser = userFrom; userEval.ToUser = userTo; userEval.Content = eval.Content; userEval.Level = eval.Level; userEval.CreateTime = DateTime.Now; userEval = UserEvalRepository.SaveOrUpdate(userEval); return JsonSuccess(UserEvalModel.From(userEval)); } catch (Exception ex) { return JsonError(ex.Message); } }
public static UserEvalModel From(UserEval userEval) { return new UserEvalModel(userEval); }
public UserEvalModel(UserEval userEval) { this.Id = userEval.Id; if (userEval.Task != null) this.TaskId = userEval.Task.Id; if (userEval.ToUser != null) { this.ToUserId = userEval.ToUser.Id; this.ToUserLoginName = userEval.ToUser.LoginName; } this.UserRole = userEval.UserRole.ToString(); if (userEval.FromUser != null) { this.FromUserId = userEval.FromUser.Id; this.FromUserLoginName = userEval.FromUser.LoginName; } this.Content = userEval.Content; this.Level = userEval.Level; this.CreateTime = userEval.CreateTime.ToJsonString(); }