public CaseStatus CreateCaseStatus(CreateCaseStatusRequest request) { var caseStatus = new Infrastructure.CaseStatus { PersonId = request.PersonId, Type = request.Type, StartDate = request.StartDate, Notes = request.Notes, CreatedBy = request.CreatedBy, Answers = new List <CaseStatusAnswer>() }; Guid identifier = Guid.NewGuid(); foreach (var answer in request.Answers) { var caseStatusAnswer = new CaseStatusAnswer { CaseStatusId = caseStatus.Id, Option = answer.Option, Value = answer.Value, StartDate = request.StartDate, CreatedAt = _systemTime.Now, CreatedBy = request.CreatedBy, GroupId = identifier.ToString() }; caseStatus.Answers.Add(caseStatusAnswer); } _databaseContext.CaseStatuses.Add(caseStatus); _databaseContext.SaveChanges(); return(caseStatus.ToDomain()); }
public static (CaseStatus, SocialCareCaseViewerApi.V1.Infrastructure.Person, List <CaseStatusAnswer>) SavePersonCaseStatusWithAnswersToDatabase( DatabaseContext databaseContext, DateTime?endDate = null, DateTime?discardedAt = null) { var person = TestHelpers.CreatePerson(); var caseStatus = TestHelpers.CreateCaseStatus(person.Id, resident: person); databaseContext.Persons.Add(person); databaseContext.CaseStatuses.Add(caseStatus); databaseContext.SaveChanges(); Guid identifier = Guid.NewGuid(); var legalStatus = new CaseStatusAnswer(); legalStatus.CaseStatusId = caseStatus.Id; legalStatus.Option = "legalStatus"; legalStatus.Value = "C1"; legalStatus.GroupId = identifier.ToString(); legalStatus.StartDate = DateTime.Today.AddDays(-10); legalStatus.CreatedAt = DateTime.Today.AddDays(-11); if (discardedAt != null) { legalStatus.DiscardedAt = discardedAt; } if (endDate != null) { legalStatus.EndDate = endDate; } var caseStatusAnswers = new List <CaseStatusAnswer>(); caseStatusAnswers.Add(legalStatus); databaseContext.CaseStatusAnswers.AddRange(caseStatusAnswers); databaseContext.SaveChanges(); return(caseStatus, person, caseStatusAnswers); }