public bool Remove(ChecklistQuestion checklistQuestion) { if (checklistQuestion == null) { return(false); } _checklistQuestions.Remove(checklistQuestion); return(true); }
public bool Remove(ChecklistQuestion checklistQuestion) { if (checklistQuestion == null) { return(false); } _context.ChecklistQuestions.Remove(checklistQuestion); _context.SaveChanges(); return(true); }
public bool AddOrUpdate(ChecklistQuestion checklistQuestion) { if (checklistQuestion == null) { return(false); } ChecklistQuestion cq = _checklistQuestions.Find((c => c.ChecklistID == checklistQuestion.ChecklistID && c.QuestionID == checklistQuestion.QuestionID)); if (cq == null) { _checklistQuestions.Add(checklistQuestion); } else { cq.Order = checklistQuestion.Order; } return(true); }
private void AddExistingQuestion() { if (SelectedExistingQuestion == null) { return; } if (TemplateQuestions.Any(t => t.Question.Equals(SelectedExistingQuestion))) { return; } var max = TemplateQuestions.Max(t => t.Order); var checklistQuestion = new ChecklistQuestion { Checklist = Checklist, Order = max == null ? 0 : max + 1, Question = SelectedExistingQuestion }; TemplateQuestions.Add(checklistQuestion); SelectedTemplateQuestion = checklistQuestion; }
private void AddNewQuestion() { if (SelectedQuestionType == null) { return; } var newQuestion = new Database.Question { QuestionType = SelectedQuestionType, Hash = MD5.Crypt($"{SelectedQuestionType.Name}-{DateTime.Now}") }; var max = TemplateQuestions.Max(t => t.Order); var checklistQuestion = new ChecklistQuestion { Checklist = Checklist, Order = max == null ? 0 : max + 1, Question = newQuestion }; TemplateQuestions.Add(checklistQuestion); SelectedTemplateQuestion = checklistQuestion; }
public DummyUserRepository() { Answer a1; Answer a2; var q1 = new ChecklistQuestion { Question = new Question { Text = "Is het antwoord nee?", QuestionType = new QuestionType { Name = "Multiple Choice" }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } }, Answers = new List <Answer>() } }; var q2 = new ChecklistQuestion { Question = new Question { Text = "Is het antwoord ja?", QuestionType = new QuestionType { Name = "Multiple Choice" }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } }, Answers = new List <Answer>() } }; a1 = new Answer { Text = "Ja", Question = q1.Question }; a2 = new Answer { Text = "Nee", Question = q2.Question }; q1.Question.Answers.Add(a1); q2.Question.Answers.Add(a2); _employees = new List <Employee> { new Employee { ID = 0, Email = "*****@*****.**", FirstName = "Daan", LastName = "Willems", TelephoneNumber = "0612345678", DateOfBirth = DateTime.Now, DateOfEmployment = DateTime.Now, WeeklySchedules = new List <WeeklySchedule> { new WeeklySchedule { Day = 1, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 2, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 3, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 4, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(0) }, new WeeklySchedule { Day = 5, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(4) }, new WeeklySchedule { Day = 6, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(24) }, new WeeklySchedule { Day = 7, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(0) } }, Address = new Address { City = "Den Bosch", Country = "Nederland", Street = "StraatWeg", Number = "22B", ZipCode = "1234AB" }, JobTitle = new JobTitle { Description = "Admin", Name = "Admin" }, Password = HashPassword("123"), Availabilities = new List <Availability> { new Availability { EmployeeID = 0, StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddDays(1), Available = true, Remark = "Daan beschikbaar" } }, InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { Inspection = new Inspection { Task = new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Test", Number = "5", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland" } } }, DateTimePlanned = DateTime.Now } }, new InspectionInspector { Inspection = new Inspection { Task = new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "test 6", Number = "5", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland" } } }, DateTimePlanned = DateTime.Now.AddDays(-2), Checklist = new Checklist { ChecklistQuestions = new List <ChecklistQuestion> { new ChecklistQuestion { Question = new Question { Text = "Is het antwoord nee?", QuestionType = new QuestionType { Name = QuestionType.MultipleChoice }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } } } }, new ChecklistQuestion { Question = new Question { Text = "Is het antwoord ja?", QuestionType = new QuestionType { Name = QuestionType.MultipleChoice }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } } } } } } } } } }, new Employee { ID = 1, Email = "*****@*****.**", FirstName = "Daan", LastName = "Ververda", Password = HashPassword("123"), Availabilities = new List <Availability> { new Availability { EmployeeID = 0, StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddDays(1), Available = true, Remark = "Daan beschikbaar" } }, TelephoneNumber = "0612345678", DateOfBirth = DateTime.Now, DateOfEmployment = DateTime.Now, Address = new Address { City = "Den Bosch", Country = "Nederland", Street = "StraatWeg", Number = "22B", ZipCode = "1234AB" }, JobTitle = new JobTitle { Description = "Admin", Name = "Admin" }, WeeklySchedules = new List <WeeklySchedule> { new WeeklySchedule { Day = 1, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 2, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 3, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(14) }, new WeeklySchedule { Day = 4, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(0) }, new WeeklySchedule { Day = 5, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(4) }, new WeeklySchedule { Day = 6, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(24) }, new WeeklySchedule { Day = 7, StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(0) } }, InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { Inspection = new Inspection { Task = new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat 5", Number = "5", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland" } } }, DateTimePlanned = DateTime.Now } } } }, new Employee { ID = 2, FirstName = "Vincent", LastName = "Brouwers" }, new Employee { ID = 3, FirstName = "Mohamed", LastName = "Hamoudi" } }; }
private void AddQuestionToChecklist(Checklist checklist, QuestionAnswerViewModel questionAnswerViewModel, UserForAuditing systemUser) { var question = _questionRepository.GetById(questionAnswerViewModel.Question.Id); if (question == null) { // adding a bespoke question var category = _categoryRepository.GetById(questionAnswerViewModel.Question.CategoryId); if (category == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, String.Format("Unknown Category - Id {0}", questionAnswerViewModel. Question.CategoryId. ToString()))); } question = Question.Create( questionAnswerViewModel.Question.Id, questionAnswerViewModel.Question.Text, category, true, // is custom (bespoke) question questionAnswerViewModel.Question.SpecificToClientId, systemUser); } else if (question.CustomQuestion && question.Title != questionAnswerViewModel.Question.Text) { // update bespoke question text question.Title = questionAnswerViewModel.Question.Text; } if (questionAnswerViewModel.Question.PossibleResponses != null) { foreach (var possibleResponse in questionAnswerViewModel.Question.PossibleResponses) { var questionResponse = _questionResponseRepository.GetById(possibleResponse.Id); if (questionResponse == null) { questionResponse = new QuestionResponse { Id = possibleResponse.Id, Title = possibleResponse.Title, SupportingEvidence = possibleResponse.SupportingEvidence, ActionRequired = possibleResponse.ActionRequired, ResponseType = possibleResponse.ResponseType, GuidanceNotes = possibleResponse.GuidanceNotes, CreatedBy = systemUser, CreatedOn = DateTime.Now, LastModifiedBy = systemUser, LastModifiedOn = DateTime.Now, ReportLetterStatement = possibleResponse.ReportLetterStatement }; } else { questionResponse.ReportLetterStatement = possibleResponse.ReportLetterStatement; } question.AddQuestionResponse(questionResponse); } } ChecklistQuestion checklistQuestion = new ChecklistQuestion() { Id = Guid.NewGuid(), Checklist = checklist, Question = question, CreatedBy = systemUser, CreatedOn = DateTime.Now, CategoryNumber = questionAnswerViewModel.CategoryNumber, QuestionNumber = questionAnswerViewModel.QuestionNumber }; checklist.UpdateQuestion(checklistQuestion, systemUser); }
public DummyTaskRepository() { Answer a1; Answer a2; var q1 = new ChecklistQuestion { Question = new Question { Text = "Is het antwoord nee?", QuestionType = new QuestionType { Name = "Multiple Choice" }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } }, Answers = new List <Answer>() } }; var q2 = new ChecklistQuestion { Question = new Question { Text = "Is het antwoord ja?", QuestionType = new QuestionType { Name = "Multiple Choice" }, AnswerSetValues = new List <AnswerSetValue> { new AnswerSetValue { Value = "Ja" }, new AnswerSetValue { Value = "Nee" }, new AnswerSetValue { Value = "Misschien" } }, Answers = new List <Answer>() } }; a1 = new Answer { Text = "Ja", Question = q1.Question }; a2 = new Answer { Text = "Nee", Question = q2.Question }; q1.Question.Answers.Add(a1); q2.Question.Answers.Add(a2); _tasks = new List <Task> { new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "testtest", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland", Province = "Gelderland", Number = "5" } }, Customer = new Customer { Name = "Mohamed", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-60), DatetimeCreated = DateTime.Now, Inspections = new List <Inspection> { new Inspection { Checklist = new Checklist { Name = "lala", ChecklistQuestions = new List <ChecklistQuestion> { q1, q1 } }, Answers = new List <Answer> { a1, a2 }, DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(50), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } }, new Inspection { DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(100), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } } } }, new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland", Province = "Gelderland", Number = "5" } }, Customer = new Customer { Name = "Daan", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-50), DatetimeCreated = DateTime.Now, Inspections = new List <Inspection> { new Inspection { Checklist = new Checklist { Name = "lala", ChecklistQuestions = new List <ChecklistQuestion> { q1, q1 } }, Answers = new List <Answer> { a1, a2 }, DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(30), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } }, new Inspection { DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(20), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } } } }, new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland", Province = "Gelderland", Number = "5" } }, Customer = new Customer { Name = "Vincent", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-40), DatetimeCreated = DateTime.Now }, new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Nijmegen", Country = "Nederland", Province = "Gelderland", Number = "5" } }, Customer = new Customer { Name = "Joep", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-40), DatetimeCreated = DateTime.Now.AddMonths(-4), Inspections = new List <Inspection> { new Inspection { Checklist = new Checklist { Name = "lala", ChecklistQuestions = new List <ChecklistQuestion> { q1, q1 } }, Answers = new List <Answer> { a1, a2 }, DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(6), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } }, new Inspection { DateTimePlanned = DateTime.Now, DateTimeDone = DateTime.Now.AddMinutes(80), InspectionInspectors = new List <InspectionInspector> { new InspectionInspector { InspectorID = 1 } } } } }, new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Arnhem", Country = "Nederland", Province = "Limburg", Number = "5" } }, Customer = new Customer { Name = "Allahu", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-40), DatetimeCreated = DateTime.Now.AddMonths(-2) }, new Task { ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Arnhem", Country = "Nederland", Province = "Gelderland", Number = "5" } }, Customer = new Customer { Name = "God", Email = "*****@*****.**" }, DateTimeEnd = DateTime.Now, DateTimeStart = DateTime.Now.AddMinutes(-40), DatetimeCreated = DateTime.Now.AddMonths(-3) }, new Task { ID = 12, DateTimeStart = new DateTime(2016, 04, 2), ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhoffstraat", ZipCode = "6524AT", City = "Nijmegen", Province = "Gelderland", Country = "Nederland", Number = "5" } }, Customer = new Customer { Name = "Christus", Email = "*****@*****.**" } }, new Task { ID = 13, DateTimeStart = new DateTime(2016, 04, 3), ParkingLot = new ParkingLot { Address = new Address { Street = "Nijhofawdfstraat", ZipCode = "652awd4AT", City = "Nijmegeawdn", Country = "Nededawrland", Province = "Gelderland", Number = "awd5" } }, Customer = new Customer { Name = "Appel", Email = "*****@*****.**" } }, new Task { ID = 1, DateTimeStart = new DateTime(2016, 04, 3), ParkingLot = new ParkingLot { ID = 1 } }, new Task { ID = 2, DateTimeStart = new DateTime(2016, 04, 3), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 3, DateTimeStart = new DateTime(2016, 04, 3), ParkingLot = new ParkingLot { ID = 2 } }, new Task { ID = 4, DateTimeStart = new DateTime(2016, 04, 3), ParkingLot = new ParkingLot { ID = 2 } }, new Task { ID = 5, DateTimeStart = new DateTime(2016, 1, 3), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 6, DateTimeStart = new DateTime(2016, 8, 3), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 7, DateTimeStart = new DateTime(2016, 04, 24), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 8, DateTimeStart = new DateTime(2016, 7, 3), ParkingLot = new ParkingLot { ID = 4 } }, new Task { ID = 9, DateTimeStart = new DateTime(2015, 04, 3), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 10, DateTimeStart = new DateTime(2014, 04, 3), ParkingLot = new ParkingLot { ID = 3 } }, new Task { ID = 11, DateTimeStart = new DateTime(2016, 05, 2), ParkingLot = new ParkingLot { ID = 5 } }, new Task { ID = 14, DateTimeStart = new DateTime(2016, 05, 2), ParkingLot = new ParkingLot { ID = 4 } } }; }
public void When_GetChecklist_is_called_With_Duplicate_Possible_Responses_For_Question_Database_Then_Only_Return_One_Instance_Of_Each() { //GIVEN var id = Guid.NewGuid(); var questionId = Guid.NewGuid(); var checklist = new Checklist(); var possibleResponseId = Guid.NewGuid(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(questionId, "Question One", category, false, new UserForAuditing()), Question.Create(questionId, "Question one", category, false, new UserForAuditing()) }; var questionResponse1 = new QuestionResponse() {Id = possibleResponseId, Title = "Acceptable"}; var questionResponse2 = new QuestionResponse() {Id = possibleResponseId, Title = "Acceptable"}; questions.First().PossibleResponses.Add(questionResponse1); questions.First().PossibleResponses.Add(questionResponse2); var checklistQuestions = new ChecklistQuestion() { Id = questionId, Checklist = checklist, Question = questions.First() }; foreach (var question in questions) { checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = question }); } checklist.Questions.Add(checklistQuestions); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.That(result.Questions.First().Question.PossibleResponses.Count, Is.EqualTo(1)); }