public static void AddExam(this HttpResponse response, int studentId, int testId, string token) { var examHeader = new ExamHeader(studentId, testId, token); var camelCaseFormatter = new JsonSerializerSettings(); camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver(); response.Headers.Add("Exam", JsonConvert.SerializeObject(examHeader, camelCaseFormatter)); response.Headers.Add("Access-Control-Expose-Headers", "Exam"); }
public static void SaveHeader(ELearningHeaderModel _header, out string message) { try { message = ""; using (var db = new PhilscanExcellenceEntities()) { if (_header.ID == Guid.Empty) //NEW { ExamHeader newHeader = new ExamHeader { ID = Guid.NewGuid(), Title = _header.Title, Description = _header.Description, CreatedDate = DateTime.Now, CreatedBy = UniversalService.CurrentUser.ID, Status = 1 }; db.Entry(newHeader).State = System.Data.Entity.EntityState.Added; } else //UPDATE { var header = db.ExamHeader.FirstOrDefault(r => r.ID == _header.ID); if (header != null) { header.Title = _header.Title; header.Description = _header.Description; header.CreatedBy = UniversalService.CurrentUser.ID; header.CreatedDate = DateTime.Now; header.Status = _header.Status; db.Entry(header).State = System.Data.Entity.EntityState.Modified; } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public Preview Preview(string Id) { List <Question> Questions = new List <Question>(); ExamHeader Header = new ExamHeader(); List <ExamBody> ExamBody = new List <ExamBody>(); List <Answer> Answers = new List <Answer>(); string HeaderQuery = $"EXECUTE SP_GetExamHeader '{Id}'"; Header = _db.Database.SqlQuery <ExamHeader>(HeaderQuery).FirstOrDefault(); string query = $"EXECUTE SP_GetQuestionsByExamId '{Id}'"; Questions = _db.Database.SqlQuery <Question>(query).ToList(); foreach (var item in Questions) { string AnswersQuery = $"EXECUTE SP_GetQuestionsAnswersByQuestionId '{item.Id}', '{Id}'"; Answers = _db.Database.SqlQuery <Answer>(AnswersQuery).ToList(); ExamBody.Add(new ExamBody { Question = item, Answers = Answers }); } Preview prev = new Preview() { Header = Header, ExamBody = ExamBody }; return(prev); }