public async Task <Guid> CreateAsync(UserAccountForCreateModel userAccountForCreateModel) { _logger.Information($"Creating user account with login '{userAccountForCreateModel.Login}'..."); if (userAccountForCreateModel.Login.Contains(':') || userAccountForCreateModel.Password.Contains(':')) { throw new UserAccountException("User account login and password must not contain following characters: ':'"); } var currentDateTime = DateTime.UtcNow; var userAccount = new UserAccountDataModel { Login = userAccountForCreateModel.Login, PasswordHash = userAccountForCreateModel.Password.GetSHA256().ToBase64(), Guid = Guid.NewGuid(), Status = UserAccountStatusEnum.Active, DateOfCreationUtc = currentDateTime, DateOfLastChangeUtc = currentDateTime }; var wasRecordSaved = await _repository.SaveAsync(userAccount); if (!wasRecordSaved) { throw new DataModelOperationException($"Error while creating user account"); } _logger.Information($"User account was successfully created ({userAccount.ToJson()})"); return(userAccount.Guid); }
public UserAccount(UserAccountDataModel dataModel) { Albums = new List <Album>(); UserID = dataModel.UserId; Name = dataModel.Name; Email = dataModel.Email; Password = dataModel.Password; Admin = dataModel.Admin; //Albums = dataModel.Albums.Select(a => new Album(a)).ToList(); }
public UserAccountDataModel Transform() { var userDataModel = new UserAccountDataModel { UserId = this.UserID, Name = this.Name, Email = this.Email, Password = this.Password, Albums = this.Albums.Select(a => a.Transform()).ToList(), Admin = this.Admin }; return(userDataModel); }
public ActionResult Register(UserAccount account) { if (!ModelState.IsValid) { ModelState.AddModelError("", "You Did Something Wrong"); return(View(account)); } account.UserID = Guid.NewGuid(); UserAccountDataModel accountData = account.Transform(); userRepository.Add(accountData); return(RedirectToAction("Login")); }
public void Add(UserAccountDataModel user) { using (var ctx = new TheContext()) { var existingUser = ctx.UsersAccounts.FirstOrDefault(x => x.UserId == user.UserId); if (existingUser == null) { ctx.UsersAccounts.Add(user); ctx.SaveChanges(); } else { existingUser.Update(user); ctx.Entry(existingUser).State = EntityState.Modified; ctx.SaveChanges(); } } }
private static void ConvertDateTimeValuesToUtc(UserAccountDataModel userAccount) { userAccount.DateOfCreationUtc = DateTime.SpecifyKind(userAccount.DateOfCreationUtc, DateTimeKind.Utc); userAccount.DateOfLastChangeUtc = DateTime.SpecifyKind(userAccount.DateOfLastChangeUtc, DateTimeKind.Utc); }
async Task WhenHandlerHandlesTheCommand() { _result = await _sut.Handle(_request); }