public async Task <IActionResult> Add(AddAccountantViewModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid data model.")); } AddAccountantCommand command = new AddAccountantCommand { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Password = model.Password }; try { await this.commandBus.SendAsync(command); } catch { return(BadRequest("Failed to add accountant.")); } return(Ok(OperationResult.Added(command.Id))); }
/// <summary> /// Create new <see cref="Data.Models.Accountant"/> based on <see cref="AddAccountantCommand"/> /// </summary> /// <param name="command">Accountant details</param> /// <returns>Data model</returns> internal Data.Models.Accountant Create(AddAccountantCommand command) { return(new Data.Models.Accountant { Id = command.Id, PasswordHash = passwordService.GenerateHash(command.Password), Email = command.Email, FirstName = command.FirstName, LastName = command.LastName, UserName = command.Email, IsActive = true, IsConfirmed = false, IsRemoved = false, CreateDate = DateTime.UtcNow, LastModificationDate = DateTime.UtcNow }); }