public ActionResult Result(int subjectId, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                ModelState.AddModelError("", "请输入姓名");
            }

            var subject = _subjectInfoService.GetSubjectById(subjectId);
            if (subject == null)
            {
                ModelState.AddModelError("", "题目不存在");
            }

            var model = new SubjectResultModel();

            if (ModelState.IsValid)
            {
                var result = _subjectResultService.GetResultByKey(subject.Id, name);
                if (result == null)
                {
                    var random = new Random((int) DateTime.Now.Ticks);
                    result = new SubjectResult()
                    {
                        Subject = subject,
                        Key = name,
                        Options = new List<SubjectOption>(),
                        ResultPictureId = subject.ResultPictureId,
                        CreateOnUtc = DateTime.UtcNow
                    };

                    var options = subject.Options.Where(o => o.IsValid);
                    var group = options.GroupBy(o => o.ResultType);
                    foreach (var item in group)
                    {
                        result.Options.Add(item.ElementAt(random.Next(item.Count())));
                    }

                    //todo create picture

                    _subjectResultService.Add(result);
                    
                }

                model = result.ToModel();
                model.ResultTitle = name + subject.ResultTitle;
            }

            return View(model);
        }
 public void Add(SubjectResult model)
 {
     _subjectResultRepository.Add(model);
 }