public GetToDoResponse GetToDoList() { var response = new GetToDoResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString()); if (user.HouseId == 0) { response.AddError("You must belong to a household to get To Do Tasks", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } response.ToDoTasks = _toDoRepository.GetToDoList(user.HouseId); } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}"); } return(response); }
public void Initialize() { _fakeAccountHelper = new FakeAccountHelper(); Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials(); _endpointHelper = new EndpointHelper(); _endpointHelper.Setup() .SetAuthenticationToken(validSessionId.ToString()); string responseContent = _endpointHelper.GetToDoItems(); _getToDoTaskResponse = JsonConvert.DeserializeObject <GetToDoResponse>(responseContent); }
/// <summary> /// This is the action that users will interact with. The reason /// for the distinction from <see cref="GetByIdAsync(int)"/>, it /// we need to preform some checking, that the requestor userId /// passed in, is equal to userId of the todo entity /// /// </summary> /// <param name="userId"></param> /// <param name="todoId"></param> /// <returns></returns> public async Task <GetToDoResponse> GetToDoForUserById(string userId, int todoId) { var todo = await GetByIdAsync(todoId); if (todo != null) { if (todo.UserId != userId) { var response = new GetToDoResponse( 0, string.Empty, false, false, new[] { new Error("authorization error", "not authorized to view this todo") }.ToList(), ResponseMessageTypes.ACTION_NOT_AUTHORIZED ); return(response); } else { var response = new GetToDoResponse( todo.Id, todo.Task, todo.Completed, true, null, ResponseMessageTypes.GET_TODO_SUCCESS ); return(response); } } else { var response = new GetToDoResponse( 0, string.Empty, false, false, null, ResponseMessageTypes.GET_TODO_FAILURE ); return(response); } }