public static User FromDto(UserDto dto) { var user = new User { Id = 1, CreationDate = dto.CreationDate, FirstName = dto.FirstName, LastName = dto.LastName, Email = dto.Email, EnergyUserName = dto.EnergyUserName, Phone = dto.Phone, }; foreach (var role in dto.Roles) { user.UserUserRoleRelation.Add(new UserUserRoleRelation { UserId = user.Id, UserRoleId = role.Id }); } if (dto.Company != null) user.CompanyId = dto.Company.Id; return user; }
public static UserDto Create(User user) { var dto = new UserDto() { Id = user.Id, CreationDate = user.CreationDate, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Phone = user.Phone, Roles = user.Roles.Select(UserRoleDto.Create).ToList(), EnergyUserName = user.EnergyUserName, AccessToken = user.AccessToken, AccessExpiry = user.AccessTokenExpiry }; if (user.Company != null) dto.Company = CompanyDto.Create(user.Company); return dto; }