Skip to content

Commit

Permalink
Make Children property readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizabeth129 committed Feb 11, 2021
1 parent e4d3d4e commit 558704e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OutOfSchool/OutOfSchool.DataAccess/Models/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Parent
[DataType(DataType.Text)]
[Required(ErrorMessage = "Last name is required")]
public string LastName { get; set; }
public virtual ICollection<Child> Children { get; set; }
public virtual IReadOnlyCollection<Child> Children { get; set; }

public Parent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public ChildrenController(IChildService childService)
[HttpGet]
public ActionResult<IEnumerable<Child>> GetChildren()
{
IEnumerable<ChildDTO> children;
try
{
children = this.childService.GetAll();
IEnumerable<ChildDTO> children = this.childService.GetAll();

This comment has been minimized.

Copy link
@dmitrykiev

dmitrykiev Feb 11, 2021

this can be improved further, we don't need the children variable at all

return this.Ok(this.childService.GetAll());

return this.Ok(children);
}
catch (Exception ex)
Expand All @@ -55,10 +54,9 @@ public ActionResult<IEnumerable<Child>> GetChildren()
[HttpGet("{id}")]
public async Task<ActionResult<ChildDTO>> GetChildById(long id)
{
ChildDTO childDTO;
try
{
childDTO = await this.childService.GetById(id).ConfigureAwait(false);
ChildDTO childDTO = await this.childService.GetById(id).ConfigureAwait(false);
return this.Ok(childDTO);
}
catch (ArgumentException ex)
Expand All @@ -81,10 +79,9 @@ public async Task<ActionResult<Child>> CreateChild(ChildDTO childDTO)
return this.BadRequest(this.ModelState);
}

ChildDTO child;
try
{
child = await this.childService.Create(childDTO).ConfigureAwait(false);
ChildDTO child = await this.childService.Create(childDTO).ConfigureAwait(false);
return this.CreatedAtAction(
nameof(this.GetChildren),
new { id = child.Id },
Expand Down

0 comments on commit 558704e

Please sign in to comment.