public TaskDTO PatchTask(int id, JsonPatchDocument <TaskDTO> taskPatchDocument)
        {
            var task = Database.Tasks.Get(id);

            if (task == null)
            {
                throw new ValidationException("Task not found", "");
            }

            // Map
            var taskDTO = taskFactory.CreateTask(task);

            // Applying patch document to dto
            taskPatchDocument.ApplyTo(taskDTO);

            // Convertion patched dto to entity
            Task resTask = taskFactory.CreateTask(taskDTO);

            task.Progress = TaskProgress.GetTaskProgress(resTask);

            Database.Tasks.Update(resTask);
            Database.Save();

            return(taskDTO);
        }
        public TaskDTO AddTask(TaskDTO taskDTO)
        {
            Task task = taskFactory.CreateTask(taskDTO);

            task.Progress = TaskProgress.GetTaskProgress(task);
            var result = Database.Tasks.Create(task);

            if (result.Status == DAL.RepositoryActionStatus.Created)
            {
                var newTask = taskFactory.CreateTask(result.Entity);
                return(newTask);
            }
            throw new DatabaseException("Something wrong with data", "");
        }
        public TaskDTO UpdateTask(int id, TaskDTO taskDTO)
        {
            Task task = taskFactory.CreateTask(taskDTO);

            task.Progress = TaskProgress.GetTaskProgress(task);

            var result = Database.Tasks.Update(task);

            if (result.Status == DAL.RepositoryActionStatus.Updated)
            {
                //Database.Save();
                var updatedTask = taskFactory.CreateTask(result.Entity);
                return(updatedTask);
            }
            else if (result.Status == DAL.RepositoryActionStatus.NotFound)
            {
                throw new ValidationException("Task not found", "");
            }
            else if (result.Status == DAL.RepositoryActionStatus.Error)
            {
                throw new DatabaseException(result.Exception.Message, "");
            }
            throw new Exception();
        }