public async Task <IActionResult> GetDetails([FromRoute] string accountId, [FromServices] IGetUserDetailsQuery getUserDetailsQuery) { try { if (accountId == null) { return(BadRequest()); } UserDetailedModel userModel = await getUserDetailsQuery.Execute(accountId); return(Ok(userModel)); } catch (ObjectNotFoundException ex) { return(NotFound(new Message("User not found."))); } catch (Exception ex) { //Log error _logger.LogError("UserController.GetDetails", "Exception was thrown", new { AccountId = accountId, Exception = ex }); return(BadRequest(new Message("Something bad happened. Try again."))); } }
public async Task <UserDetailedModel> Execute(string accountId) { try { //Get user User user = await(await _userRepo.FindAsync(x => x.AccountId == accountId)).SingleOrDefaultAsync(); if (user == null) { throw new ObjectNotFoundException("User not found"); } UserDetailedModel userModel = new UserDetailedModel() { AccountId = user.AccountId, FirstName = user.FirstName, LastName = user.LastName, Gender = user.Gender, CreateDate = user.CreateDate, ModifiedDate = user.ModifiedDate }; //Fill contacts if any if (user.Contacts.Count != 0) { userModel.Contacts = user.Contacts.Select(c => new ContactModel() { Type = c.Type, Value = c.Value }).ToList(); } //Get user roles if any if (user.RoleIds.Count != 0) { userModel.Roles = await GetUserRoles(user.RoleIds); } return(userModel); } catch (ObjectNotFoundException ex) { throw; } catch (Exception ex) { //Log _logger.LogError("GetUserDetailsQuery.Execute", "Exception occurred", new { AccountId = accountId, Exception = ex }); throw; } }
public UserDetailedModel ShowUserDetails(string id) { //var id = int.Parse(idNum); var user = this.data.Users.Find(id); var userToReturn = new UserDetailedModel() { Id = user.Id, UserName = user.UserName }; return(userToReturn); }