public static UserProfile MapRelatedUserDtoToProfile(RelatedUserDto relatedUserDto) { return(new UserProfile() { Id = relatedUserDto.UserId, FirstName = relatedUserDto.FirstName, LastName = relatedUserDto.LastName, CurrentTradeRole = Mapper.MapTradeRoleDtoToEntity(relatedUserDto.CurrentTradeRole) }); }
public async Task UpsertRelatedUser(int id, RelatedUserDto relatedUserDto) { try { var userIdIsValid = await CheckUserById(id); if (!userIdIsValid) { return; } var relatedUserIdIsValid = await CheckUserById(relatedUserDto.RelatedUserId); if (!relatedUserIdIsValid) { return; } var fullUser = await _repo.GetFullUser(id); if (fullUser.ContactPersons == null) { fullUser.ContactPersons = new List <RelatedUser>(); } if (!fullUser.ContactPersons.Any(u => u.RelatedUserID == relatedUserDto.RelatedUserId)) { fullUser.ContactPersons.Add(new RelatedUser { RelationType = relatedUserDto.RelationType, UserID = id, RelatedUserID = relatedUserDto.RelatedUserId }); } else { var contactPerson = fullUser.ContactPersons.First(u => u.RelatedUserID == relatedUserDto.RelatedUserId); contactPerson.RelationType = relatedUserDto.RelationType; } await _repo.Update(id, fullUser); } catch (Exception e) { _logger.LogException(e); throw e; } }