diff options
| -rw-r--r-- | API/Service/UserService.cs | 4 | ||||
| -rw-r--r-- | Models/Classes/UserMapper.cs | 28 |
2 files changed, 25 insertions, 7 deletions
diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index 0bc4939..0bb53c0 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -24,9 +24,9 @@ namespace API.Service { //TODO: MAKE VALIDATIONS OF PROPER REQUEST - //Map UserDTO -> User + User user = Mapper.UserDtoToUser(userDTO); + await this._dbRepository.AddAsync(user); - //await this._dbRepository.AddAsync(newUser); return HttpStatusCode.OK; } diff --git a/Models/Classes/UserMapper.cs b/Models/Classes/UserMapper.cs index 7b61a57..3969818 100644 --- a/Models/Classes/UserMapper.cs +++ b/Models/Classes/UserMapper.cs @@ -1,7 +1,25 @@ +using Models.DTOs; +using System.Reflection; + namespace Models.Classes { - public class UserMapper - { - - } -}
\ No newline at end of file + public static class Mapper + { + /// <summary> + /// Mapps UserDTO to a User + /// </summary> + /// <param name="userDTO">UserDTO that is going to be mapped</param> + /// <returns>Mapped User</returns> + public static User UserDtoToUser(UserDTO userDTO) + { + User user = new User(); + foreach(PropertyInfo property in user.GetType().GetProperties()) + { + var neshto = property.GetValue(userDTO, null); + property.SetValue(user, neshto, null); + } + + return user; + } + } +} |
