File tree Expand file tree Collapse file tree 12 files changed +161
-10
lines changed
Pds.Core/Exceptions/Person
Pds.Services.Models/Person Expand file tree Collapse file tree 12 files changed +161
-10
lines changed Original file line number Diff line number Diff line change 33using System . ComponentModel . DataAnnotations ;
44using Pds . Api . Contracts . Person ;
55
6- namespace Pds . Api . Contracts . Cost
6+ namespace Pds . Api . Contracts . Person
77{
88 public class EditPersonRequest
99 {
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace Pds . Api . Contracts . Person
4+ {
5+ public class EditPersonResponse
6+ {
7+ public Guid Id { get ; set ; }
8+ }
9+ }
Original file line number Diff line number Diff 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 ; }
Original file line number Diff line number Diff line change 1111using Pds . Api . Contracts . Person ;
1212using Pds . Data . Entities ;
1313using Pds . Services . Interfaces ;
14+ using Pds . Services . Models . Person ;
1415
1516namespace 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>
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 44using System . Threading . Tasks ;
55using Microsoft . EntityFrameworkCore ;
66using Pds . Core . Enums ;
7+ using Pds . Core . Exceptions ;
78using Pds . Data . Entities ;
89using Pds . Data . Repositories . Interfaces ;
910
Original file line number Diff line number Diff line change 1616using Pds . Services . Models . Client ;
1717using Pds . Services . Models . Content ;
1818using Pds . Services . Models . Cost ;
19+ using Pds . Services . Models . Person ;
1920using Pds . Web . Models . Content ;
2021
2122namespace 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 (
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Threading . Tasks ;
44using Pds . Data . Entities ;
5+ using Pds . Services . Models . Person ;
56
67namespace 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 ) ;
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments