public AuditDetailViewModel(Audit audit)
 {
     this.AuditId = audit.Id;
     this.Items = audit.Items.Select(x => new AuditDetailItemViewModel {
         Id = x.Id,
         Key = x.Key,
         UserValue = x.UserValue,
         AuditorValue = x.AuditorValue,
         Comment = x.Comment
     }).ToArray();
 }
        public ActionResult AuditForm(string userId)
        {
            var auditor = this.GetAuthUser();
            var context = ApplicationDbContext.Create();
            var questionnaire = context.Questionnaires.Single(x => x.User.Id == userId);
            var audit = context.Audits.SingleOrDefault(x => x.User.Id == questionnaire.User.Id);
            if (audit == null) {
                audit = new Audit() {
                    User = context.Users.Single(x=>x.Id == userId),
                    Auditor = context.Users.Single(x=>x.Id== auditor.Id),
                };
                foreach (var item in questionnaire.Items) {
                    audit.Items.Add(new AuditItem() {
                        Key = item.Key,
                        UserValue = item.Value,
                    });
                }
                context.Audits.Add(audit);
                context.SaveChanges();
            }

            var model = new AuditDetailViewModel(audit);
            return View(model);
        }