Exemplo n.º 1
0
        public AddToDoResponse AddToDoItem([FromBody] AddToDoTaskRequest toDoTaskRequest)
        {
            var response = new AddToDoResponse();

            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 add To Do Tasks", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }
                response.Id = _toDoRepository.AddToDoTask(toDoTaskRequest, user.HouseId);

                response.Notifications = new List <string>
                {
                    $"The task '{toDoTaskRequest.Title}' has been added"
                };
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", toDoTaskRequest, exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", toDoTaskRequest);
            }

            return(response);
        }