Reputation: 1249
All of the fields except for Full_name is being caught when I try to POST or PUT. Can you help?
Here's my Models and DTOs.
public class AbilityScore : BaseEntity
{
public string Desc { get; set; } = string.Empty;
public string Full_name { get; set; } = string.Empty;
public string Index { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
}
public record struct AbilityScoreCreateRequest(
string Index,
string Name,
string Full_name,
string Desc,
string Url
);
public record struct AbilityScoreResponse(
int Id,
string Index,
string Name,
string Full_name,
string Desc,
string Url
);
public record struct AbilityScoreUpdateRequest(
string Index,
string Name,
string Full_name,
string Desc,
string Url
);
Here are my Services
public interface IAbilityScoreService
{
Task<List<AbilityScoreResponse>> Create(AbilityScoreCreateRequest request);
Task<List<AbilityScoreResponse>?> Update(int id, AbilityScoreUpdateRequest request);
}
public class AbilityScoreService : IAbilityScoreService
{
private readonly IAbilityScoreRepository _abilityScoreRepository;
public AbilityScoreService(IAbilityScoreRepository abilityScoreRepository)
{
_abilityScoreRepository = abilityScoreRepository;
}
public async Task<List<AbilityScoreResponse>> Create(AbilityScoreCreateRequest request)
{
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
request.Full_name = textInfo.ToTitleCase(request.Full_name);
request.Index = request.Index.ToLower();
request.Name = request.Index.ToUpper();
request.Url = $"/api/ability-scores/{request.Index}";
var newObject = request.Adapt<AbilityScore>();
var result = await _abilityScoreRepository.Create(newObject);
return result.Adapt<List<AbilityScoreResponse>>();
}
public async Task<List<AbilityScoreResponse>?> Update(int id, AbilityScoreUpdateRequest request)
{
try
{
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
request.Full_name = textInfo.ToTitleCase(request.Full_name);
request.Index = request.Index.ToLower();
request.Name = request.Index.ToUpper();
request.Url = $"/api/ability-scores/{request.Index}";
var updatedObject = request.Adapt<AbilityScore>();
var result = await _abilityScoreRepository.Update(id, updatedObject);
return result.Adapt<List<AbilityScoreResponse>>();
}
catch (EntityNotFoundException)
{
return null;
}
}
Let me know if you need more to help me diagnose.
Thanks!
Upvotes: 0
Views: 9