Ejemplo n.º 1
0
        public async Task <IActionResult> CreateTask([FromBody] TaskItem payload)
        {
            payload.Column = EnumTaskColumns.Backlog;
            await _repository.Add(payload);

            return(Ok(await _repository.GetAll()));
        }
        public IActionResult Create([FromBody] TaskItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _repository.Add(item);

            return(CreatedAtRoute("GetTask", new { id = item.Id }, item));
        }
Ejemplo n.º 3
0
        public TaskItem AddTaskItem(TaskItemModel task)
        {
            var item = new TaskItem()
            {
                Name        = task.Name,
                Description = task.Description,
                Priority    = task.Priority,
                TaskId      = task.TaskId
            };

            repository.Add(item);
            return(item);
        }
Ejemplo n.º 4
0
        public CreateTaskOutput Execute(CreateTaskInput input)
        {
            if (input is null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.IsValid())
            {
                //create new Domain TaskItem from the supplied input data
                TaskItem newTask = InputToTaskItem(input);

                if (taskManager.Add(newTask))
                {
                    ITaskItemRepository taskItemRepo = taskItemRepositoryFactory.New();

                    //Create a TaskItemDAL to save to the database
                    TaskItemDAL taskItemDAL = TaskItemAndInputToDAL(newTask, input);

                    //add the new TaskItemDAL to the database
                    if (taskItemRepo.Add(taskItemDAL))
                    {
                        //save the changed make to the TaskItemRepository
                        if (taskItemRepo.Save())
                        {
                            //create DTO to return as Output data
                            TaskItemDTO taskItemDTO = InputToTaskItemDTO(input);

                            //fill output data and return
                            return(new CreateTaskOutput {
                                Success = true, TaskItemDTO = taskItemDTO
                            });
                        }
                        else
                        {
                            //failed to save state of repository
                            //remove taskItem from domain TaskManager
                            if (!taskManager.Remove(newTask))
                            {
                                //TaskItem could not be removed. we're now screwed . . .
                                //TODO: decide what to do here
                            }

                            return(new CreateTaskOutput {
                                Success = false, Error = "Unable to save the new Task."
                            });
                        }
                    }
                    else
                    {
                        //failed to save task to repository
                        //remove taskItem from domain TaskManager
                        if (!taskManager.Remove(newTask))
                        {
                            //TaskItem could not be removed. we're now screwed . . .
                            //TODO: decide what to do here
                        }

                        return(new CreateTaskOutput {
                            Success = false, Error = "Unable to save the new Task."
                        });
                    }
                }
                else
                {
                    //unable to add new TaskItem to domain TaskManager
                    return(new CreateTaskOutput {
                        Success = false, Error = "Unable to process the new Task."
                    });
                }
            }
            else
            {
                //Input is not valid
                return(new CreateTaskOutput {
                    Success = false, Error = input.GetErrorMessage()
                });
            }
        }