private void Copy(UserCrDto userCrDto, User user, bool copyNickname, bool copyPassword) { user.city_id = userCrDto.CityId; user.university_id = userCrDto.UniversityId; user.description = userCrDto.Description; user.email = userCrDto.Email; user.group = userCrDto.Group; user.name = userCrDto.Name; user.phone = userCrDto.Phone; user.surname = userCrDto.Surname; if (copyNickname) { user.nickname = userCrDto.Nickname; } if (copyPassword) { var encryption = new HashEncryption(); encryption.HashPassword(user); } }
public CrResult <UserDto> Create(UserCrDto userCrDto) { var crResult = new CrResult <UserDto>(); CheckRegisterData(userCrDto, crResult, true, true); if (crResult.ActionResult == ActionResult.Success) { var user = Converter.ConvertToUser(userCrDto); var encryption = new HashEncryption(); encryption.HashPassword(user); try { var createdUser = _context.User.Add(user); _context.SaveChanges(); crResult.CreatedObject = Converter.ConvertToUserDto(createdUser); } catch (DbUpdateException) { crResult.ActionResult = ActionResult.DatabaseError; } } return(crResult); }