public static void Initialize() { if (!isInitialized) { #region Inspection isInitialized = true; Inspection inspection_1 = new Inspection { CreatedTime = DateTime.Now, Type = InspectionType.ProjectInspection, IsSafe = IsSafe.NotComplited, LocationWhenCreated = "some location", ModifiedTime = DateTime.Now, Name = "Inspection 1 for ProjectInspection", Id = 1 }; Inspection inspection_2 = new Inspection { CreatedTime = DateTime.Now, Type = InspectionType.SubcontractorInspection, IsSafe = IsSafe.NotComplited, LocationWhenCreated = "some location", ModifiedTime = DateTime.Now, Name = "Inspection 1 for SubcontractorInspection", Id = 2 }; inspections.Add(inspection_1); inspections.Add(inspection_2); #endregion #region Category categories.Add(new Category { Id = 1, Name = "Administration" }); categories.Add(new Category { Id = 2, Name = "Asbestos" }); categories.Add(new Category { Id = 3, Name = "Confined Space" }); categories.Add(new Category { Id = 4, Name = "Control of Hazardous Energy" }); categories.Add(new Category { Id = 5, Name = "Demolition" }); categories.Add(new Category { Id = 6, Name = "Electrical Safety" }); categories.Add(new Category { Id = 7, Name = "Environmental" }); #endregion #region Note List<string> noteContents = new List<string>(); noteContents.Add("question note_1"); noteContents.Add("question note_2"); noteContents.Add("question note_3"); noteContents.Add("question note_4"); noteContents.Add("inspection note_1"); noteContents.Add("inspection note_2"); noteContents.Add("ToDelete"); int count = 1; foreach (string content in noteContents) { Note note = new Note { Id = count, Content = content, Type = NoteType.Text }; notes.Add(note); count++; } questionNote.Add(1, 1); questionNote.Add(2, 1); questionNote.Add(3, 2); questionNote.Add(4, 3); inspectionNote.Add(5, 1); inspectionNote.Add(6, 1); #endregion #region Question List<string> questionNames = new List<string>(); questionNames.Add("Accountability Plan Utilized"); questionNames.Add("Address Displayed On Perimeter"); questionNames.Add("Adequate 1st Aid Kits"); questionNames.Add("Adequate Eyewash Stations"); questionNames.Add("Annual Program Evaluation"); questionNames.Add("Competent Persons List"); questionNames.Add("Coord With Local FD"); questionNames.Add("CSAP Enrollment Complete"); int counter = 1; foreach (string name in questionNames) { Question question = new Question { Id = count, CreatedTime = DateTime.Now, IsSafe = IsSafe.NotComplited, ModifiedTime = DateTime.Now, Text = name, NotesCounter = questionNote.Where(n => n.Value == counter).Count() }; questions.Add(question); counter++; } #endregion } }
private Response EditQuestionModificationTime(Inspection inspection, Question question) { Response response = new Response(); bool result = dal.SetQuestionModificationTime(inspection.UUID, question.Id, question.ModifiedTime, userId); switch (result) { case true: response = EditInspectionModificationTime(inspection); if(response.Result == QueryResult.Fail) { //TODO rollback } break; case false: response.Result = QueryResult.Fail; response.Message = "Cannot edit question modification time."; isInvalidData = true; break; } return response; }
public ComplexObjects.Question GetQuestion(string inspectionUUID, int questionId) { CSInspectionDatabaseModel.Question questionFromDBModel = context.Questions.Where(q => q.Id == questionId).Select(q => q).FirstOrDefault(); ComplexObjects.Question question = new ComplexObjects.Question(); question.Id = questionFromDBModel.Id; question.Text = questionFromDBModel.Text; question.OrderNumber = questionFromDBModel.OrderNumber; question.CategoryId = questionFromDBModel.CategoryId; int inspectionId = context.Inspections.Where(i => i.UUID == inspectionUUID).Select(i => i.Id).FirstOrDefault(); //check if answered if(context.Answers.Any(a => a.InspectionId == inspectionId && a.QuestionId == questionId)) { //get answer by inspection id and questionId CSInspectionDatabaseModel.Answer answer = context.Answers.Where(a => a.QuestionId == questionId && a.InspectionId == inspectionId).Select(a => a).FirstOrDefault(); question.ModifiedTime = answer.ModifiedTime; question.PositivePercent = answer.PositivePercent; question.NegativePercent = answer.NegativePercent; question.NotesCounter = context.AnswerNotes.Where(an => an.AnswerId == answer.Id).Count(); } else { question.PositivePercent = 0; question.NegativePercent = 0; question.NotesCounter = 0; } return question; }