Skip to content

Commit

Permalink
Simplify code which creates a new assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHowellDfE committed Feb 8, 2024
1 parent fd05516 commit 399d8eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ public ServiceAssessmentService.Domain.Model.AssessmentRequest ToDomainModel()

public static Database.Entities.AssessmentRequest FromDomain(Domain.Model.AssessmentRequest domainModel)
{
throw new NotImplementedException();
var entity = new Database.Entities.AssessmentRequest
{
Id = domainModel.Id,
Name = domainModel.Name,
PhaseConcludingId = domainModel.PhaseConcluding?.Id,
AssessmentTypeRequestedId = domainModel.AssessmentType?.Id,
IsReassessment = domainModel.IsReassessment,
IsProjectCodeKnown = domainModel.IsProjectCodeKnown,
ProjectCode = domainModel.ProjectCode,
PhaseStartDate = domainModel.PhaseStartDate,
IsPhaseEndDateKnown = domainModel.IsPhaseEndDateKnown,
PhaseEndDate = domainModel.PhaseEndDate,
Description = domainModel.Description,
CreatedUtc = domainModel.CreatedAt.UtcDateTime,
UpdatedUtc = domainModel.UpdatedAt.UtcDateTime,
};

return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,17 @@ public AssessmentRequestRepository(DataContext dbContext, ILogger<AssessmentRequ
return assessmentRequest;
}

public async Task<Domain.Model.AssessmentRequest?> CreateAsync(Domain.Model.AssessmentRequest assessmentRequest)
public async Task<Domain.Model.AssessmentRequest?> CreateAsync()
{
var entity = new Database.Entities.AssessmentRequest
var entity = Database.Entities.AssessmentRequest.FromDomain(new Domain.Model.AssessmentRequest()
{
Id = assessmentRequest.Id,
Name = assessmentRequest.Name,
PhaseConcluding = Database.Entities.Phase.FromDomain(assessmentRequest.PhaseConcluding),
AssessmentTypeRequested = Database.Entities.AssessmentType.FromDomain(assessmentRequest.AssessmentType),
PhaseStartDate = assessmentRequest.PhaseStartDate,
PhaseEndDate = assessmentRequest.PhaseEndDate,
Description = assessmentRequest.Description,
};
Id = Guid.NewGuid(),
});

_dbContext.AssessmentRequests.Add(entity);
await _dbContext.SaveChangesAsync();

return assessmentRequest;
return entity.ToDomainModel();
}

public async Task<Domain.Model.AssessmentRequest?> DeleteAsync(Guid id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ public StartNewPageModel(AssessmentRequestRepository assessmentRequestRepository
public async Task<IActionResult> OnPost()
{
_logger.LogInformation("Attempting to create a new assessment request");

var blankRequest = new Domain.Model.AssessmentRequest()

var assessmentRequest = await _assessmentRequestRepository.CreateAsync();
if(assessmentRequest is null)
{
Id = Guid.NewGuid(),
};

var assessmentRequest = await _assessmentRequestRepository.CreateAsync(blankRequest);
_logger.LogError("Failed to create a new assessment request");
return RedirectToPage("/Error");
}

_logger.LogInformation("Created new assessment request with ID {Id}", assessmentRequest.Id);

return RedirectToPage("/Book/Request/Question/PhaseConcluding", new { assessmentRequest.Id });
Expand Down

0 comments on commit 399d8eb

Please sign in to comment.