public bool AddTaskForUser(int userId, string description, IResponseModel model)
 {
     try
     {
         _taskService.AddTaskForUser(userId, new UserTask(description));
     }
     catch (AddUserTaskException e)
     {
         model.AddAttribute("action_result", DataProvider.GetErrorMessage(e));
         return(false);
     }
     return(true);
 }
示例#2
0
        private void GetMessageForModel(int userId, string description)
        {
            var task = new UserTask(description);

            try
            {
                _taskService.AddTaskForUser(userId, task);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private string GetMessageForModel(int userId, string description)
        {
            var task   = new UserTask(description);
            int result = _taskService.AddTaskForUser(userId, task);

            if (result == -1)
            {
                return("Invalid userId");
            }

            if (result == -2)
            {
                return("User not found");
            }

            if (result == -3)
            {
                return("The task already exists");
            }

            return(null);
        }
示例#4
0
        public bool AddTaskForUser(int userId, string description, IResponseModel model)
        {
            var task = new UserTask(description);

            try
            {
                taskService.AddTaskForUser(userId, task);
                return(true);
            }
            catch (ArgumentOutOfRangeException)
            {
                model?.AddAttribute(ModelErrorKey, "Invalid userId");
            }
            catch (UserNotFoundException)
            {
                model?.AddAttribute(ModelErrorKey, "User not found");
            }
            catch (TaskAlreadyExistsException)
            {
                model?.AddAttribute(ModelErrorKey, "The task already exists");
            }

            return(false);
        }