Skip to content

Commit 4332edc

Browse files
committed
added basic person update
1 parent 375a941 commit 4332edc

File tree

12 files changed

+161
-10
lines changed

12 files changed

+161
-10
lines changed

Pds/Pds.Api.Contracts/Person/EditPersonRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.ComponentModel.DataAnnotations;
44
using Pds.Api.Contracts.Person;
55

6-
namespace Pds.Api.Contracts.Cost
6+
namespace Pds.Api.Contracts.Person
77
{
88
public class EditPersonRequest
99
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Pds.Api.Contracts.Person
4+
{
5+
public class EditPersonResponse
6+
{
7+
public Guid Id { get; set; }
8+
}
9+
}

Pds/Pds.Api.Contracts/Person/PersonDto.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class PersonDto
1616

1717
public string FullName { get; set; }
1818

19+
public string Country { get; set; }
20+
1921
public string City { get; set; }
2022

2123
public string Location { get; set; }

Pds/Pds.Api/Controllers/PersonController.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Pds.Api.Contracts.Person;
1212
using Pds.Data.Entities;
1313
using Pds.Services.Interfaces;
14+
using Pds.Services.Models.Person;
1415

1516
namespace Pds.Api.Controllers
1617
{
@@ -109,6 +110,32 @@ public async Task<IActionResult> Create(CreatePersonRequest request)
109110
}
110111
}
111112

113+
/// <summary>
114+
/// Edit person
115+
/// </summary>
116+
/// <returns></returns>
117+
[HttpPut]
118+
[ProducesResponseType(typeof(EditPersonResponse), StatusCodes.Status200OK)]
119+
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
120+
public async Task<IActionResult> Edit(EditPersonRequest request)
121+
{
122+
try
123+
{
124+
if (ModelState.IsValid)
125+
{
126+
var editCostModel = mapper.Map<EditPersonModel>(request);
127+
var costId = await personService.EditAsync(editCostModel);
128+
return Ok(new EditPersonResponse{Id = costId});
129+
}
130+
131+
return BadRequest();
132+
}
133+
catch (Exception e)
134+
{
135+
return ExceptionResult(e);
136+
}
137+
}
138+
112139
/// <summary>
113140
/// Delete specified person
114141
/// </summary>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Pds.Core.Exceptions.Person
5+
{
6+
public class PersonEditException : Exception, IApiException
7+
{
8+
public List<string> Errors { get; }
9+
10+
public PersonEditException(List<string> errors)
11+
{
12+
Errors = errors;
13+
}
14+
15+
public PersonEditException(string message)
16+
: base(message)
17+
{
18+
Errors = new List<string> { message };
19+
}
20+
21+
public PersonEditException(string message, Exception inner)
22+
: base(message, inner)
23+
{
24+
}
25+
}
26+
}

Pds/Pds.Data/Repositories/PersonRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Microsoft.EntityFrameworkCore;
66
using Pds.Core.Enums;
7+
using Pds.Core.Exceptions;
78
using Pds.Data.Entities;
89
using Pds.Data.Repositories.Interfaces;
910

Pds/Pds.Mappers/ApiMappingProfile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Pds.Services.Models.Client;
1717
using Pds.Services.Models.Content;
1818
using Pds.Services.Models.Cost;
19+
using Pds.Services.Models.Person;
1920
using Pds.Web.Models.Content;
2021

2122
namespace Pds.Mappers
@@ -133,6 +134,11 @@ public ApiMappingProfile()
133134
CreateMap<EditClientRequest, EditClientModel>();
134135
CreateMap<EditCostRequest, EditCostModel>();
135136
CreateMap<EditBillRequest, EditBillModel>();
137+
CreateMap<EditPersonRequest, EditPersonModel>()
138+
.ForMember(
139+
dest => dest.BrandsIds,
140+
opt => opt
141+
.MapFrom(p => p.Brands.Where(b=>b.IsSelected).Select(b=>b.Id)));
136142
CreateMap<CreateContentBillDto, CreateContentBillModel>();
137143
CreateMap<CreateContentRequest, CreateContentModel>()
138144
.ForMember(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Pds.Services.Models.Person
5+
{
6+
public class EditPersonModel
7+
{
8+
public Guid Id { get; set; }
9+
public string FirstName { get; set; }
10+
11+
public string LastName { get; set; }
12+
13+
public string ThirdName { get; set; }
14+
15+
public string Country { get; set; }
16+
17+
public string City { get; set; }
18+
19+
public string Topics { get; set; }
20+
21+
public string Info { get; set; }
22+
23+
public int? Rate { get; set; }
24+
25+
public List<Guid> BrandsIds { get; set; }
26+
}
27+
}

Pds/Pds.Services/Interfaces/IPersonService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using Pds.Data.Entities;
5+
using Pds.Services.Models.Person;
56

67
namespace Pds.Services.Interfaces
78
{
@@ -13,6 +14,8 @@ public interface IPersonService
1314

1415
Task<Guid> CreateAsync(Person person);
1516

17+
Task<Guid> EditAsync(EditPersonModel model);
18+
1619
Task ArchiveAsync(Guid personId);
1720

1821
Task UnarchiveAsync(Guid personId);

Pds/Pds.Services/Services/ContentService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public async Task<Guid> EditAsync(EditContentModel model)
108108
content.ReleaseDate = model.ReleaseDate.Date;
109109
content.EndDate = model.EndDate?.Date;
110110
content.PersonId = model.PersonId != null && model.PersonId.Value == Guid.Empty ? null : model.PersonId;
111+
111112
if (model.Bill != null && content.Bill != null) // Just update existed bill
112113
{
113114
content.Bill.ClientId = model.Bill.ClientId;

0 commit comments

Comments
 (0)