Exemplo n.º 1
0
        public async Task <Models.Task> EditTask(Models.Task task)
        {
            var uri   = UriFactory.CreateEndpointUri("tasks/update");
            var param = JsonContentFactory.CreateContent(task);
            HttpResponseMessage response;

            try
            {
                response = await Client.PutAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <Models.Task>(content));
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Exemplo n.º 2
0
        public async Task SaveTaskAsync(TaskBo taskBo)
        {
            Models.Task task = _mapper.Map <Models.Task>(taskBo);
            if (task.Id == 0)
            {
                const int BACKLOG_STATUS_ID = 1;
                decimal   maxPriority       = _dbContext.Tasks
                                              .Where(t => t.StatusId == BACKLOG_STATUS_ID)
                                              .OrderByDescending(t => t.Priority)
                                              .Select(t => t.Priority)
                                              .FirstOrDefault();

                task.Priority = maxPriority + 1;
                task.StatusId = BACKLOG_STATUS_ID;
                _dbContext.Tasks.Add(task);
            }
            else
            {
                Models.Task existingTask = await _dbContext.Tasks
                                           .FirstOrDefaultAsync(t => t.Id == task.Id);

                if (existingTask == null)
                {
                    return;
                }

                existingTask.Summary = task.Summary;
            }

            await _dbContext.SaveChangesAsync();
        }
        public async Task AddTask(Models.Task task)
        {
            var storageTask = _storageTaskMapper.Map(task);
            await _storage.Tasks.AddAsync(storageTask);

            await _storage.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public Task <Models.Task> GetHumanTaskAsync(long TaskeId)
        {
            Login();

            var request = new RestRequest(_ApiResource + "/humanTask/{id}", Method.GET)
                          .AddCookies(_Cookies);

            request.AddParameter("id", TaskeId, ParameterType.UrlSegment);

            Models.Task task = null;

            try
            {
                task = HandleResponse <Models.Task>(_RestClient.Execute(request));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Logout();
            }

            return(Task.FromResult(task));
        }
Exemplo n.º 5
0
 public async Task CreateTask(Models.Task Task)
 {
     if (_TaskRepository.GetOne(e => e.Content == Task.Content) == null)
     {
         _TaskRepository.Add(Task);
         await _unitOfWork.SaveChanges();
     }
 }
Exemplo n.º 6
0
        public async Task CreateTask(Models.Task task, string userId)
        {
            task.UserId = userId;

            _context.Add(task);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task Edit(Models.Task task)
        {
            var oldTask = await GetTaskById(task.Id);

            var prevStatus = oldTask.Status;


            if (task.Status == Models.TaskStatus.Completed && prevStatus != Models.TaskStatus.Completed)
            {
                var tasksWithPath = _context.taskWithSubtreePaths.FromSql($"call getAllTaskDescendants({task.Id})");

                bool canBeCompleted = await(from taskWithPath in tasksWithPath
                                            join t in _context.Tasks
                                            on taskWithPath.Id equals t.Id
                                            where taskWithPath.Id != task.Id
                                            select t.Status)
                                      .AllAsync(s => s == Models.TaskStatus.InPerform || s == Models.TaskStatus.Suspended || s == Models.TaskStatus.Completed);

                if (canBeCompleted)
                {
                    var tasks = await(from taskWP in tasksWithPath
                                      join tk in _context.Tasks
                                      on taskWP.Id equals tk.Id
                                      select tk).ToListAsync();

                    foreach (var tsk in tasks)
                    {
                        tsk.Status = Models.TaskStatus.Completed;
                    }

                    _context.Tasks.UpdateRange(tasks);

                    task.ActualCompletionDate = DateTime.Now;
                }
                else
                {
                    task.Status = oldTask.Status;
                }
            }

            oldTask.Status = task.Status;

            oldTask.Performers = task.Performers;

            oldTask.Name = task.Name;

            oldTask.CompletionTime = task.CompletionTime;

            oldTask.ActualCompletionDate = task.ActualCompletionDate;

            oldTask.Description = task.Description;

            oldTask.PlannedLaboriousness = task.PlannedLaboriousness;

            await _context.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public async Task GetTaskAsync_Should_Return_Exception_When_Id_Is_Null()
        {
            //Arrange

            //Act
            Models.Task t = await taskRepositoryMock.Object.GetTaskAsync(Guid.Empty);

            //Assert
            Assert.Null(t);
        }
Exemplo n.º 9
0
        public async Task UpdateTask(Models.Task updatedTask)
        {
            var Task = _TaskRepository.GetOne(e => e.Id == updatedTask.Id);

            Task.Content    = updatedTask.Content;
            Task.Done       = updatedTask.Done;
            Task.InProgress = updatedTask.InProgress;
            _TaskRepository.Update(Task);
            await _unitOfWork.SaveChanges();
        }
Exemplo n.º 10
0
        public async Task GetTaskAsync_Should_Filter_Category_Tasks()
        {
            //Arrange

            //Act
            Models.Task t =
                await taskRepositoryMock.Object.GetTaskAsync(Guid.Parse("1316726a-a651-4cef-800d-a74746ca3d74"));

            //Assert
            Assert.Null(t.Category.Tasks);
        }
        public async Task UpdateTask(Models.Task task)
        {
            var storageTask = await _storage.GetTasks().FirstOrDefaultAsync(t => t.Id == task.Id);

            if (storageTask is null)
            {
                throw new TasksNotFoundException(task.Id);
            }
            _storageTaskMapper.Map(task, storageTask);
            _storage.Tasks.Update(storageTask);
            await _storage.SaveChangesAsync();
        }
Exemplo n.º 12
0
        public async Task GetTaskAsync_Should_Filter_Requirement_Task()
        {
            //Arrange

            //Act
            Models.Task t =
                await taskRepositoryMock.Object.GetTaskAsync(Guid.Parse("1316726a-a651-4cef-800d-a74746ca3d74"));

            //Assert
            foreach (Requirement tRequirement in t.Requirements)
            {
                Assert.Null(tRequirement.Task);
            }
        }
        public IActionResult Create(Models.Task task)
        {
            if (task == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var db = new TaskDbContext())
            {
                db.Tasks.Add(task);
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 14
0
        public async Task UpdateTaskAsync(int taskId, decimal priority, int statusId)
        {
            Models.Task task = await _dbContext.Tasks
                               .FirstOrDefaultAsync(t => t.Id == taskId);

            if (task == null)
            {
                return;
            }

            task.Priority = priority;
            task.StatusId = statusId;

            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 15
0
        public async Task <Models.Task> Create(Models.Task task)
        {
            try
            {
                await _baseContext.Tasks.AddAsync(task);

                await _baseContext.SaveChangesAsync();

                return(task);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
        public IActionResult Edit(Models.Task task, int?id)
        {
            if (task == null || id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var db = new TaskDbContext())
            {
                var taskToEdit = db.Tasks.Find(id);
                if (taskToEdit == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                taskToEdit.Title = task.Title;
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 17
0
        public async Task GetTaskAsync_Should_Include_Related_Data()
        {
            //Arrange

            //Act
            Models.Task t =
                await taskRepositoryMock.Object.GetTaskAsync(Guid.Parse("1316726a-a651-4cef-800d-a74746ca3d74"));

            //Assert
            Assert.NotNull(t);
            Assert.Equal(Guid.Parse("1316726a-a651-4cef-800d-a74746ca3d74"), t.Id);
            Assert.NotNull(t.Instruction);
            Assert.NotNull(t.Category);
            Assert.NotNull(t.Requirements);
            Assert.NotEmpty(t.Requirements);
            foreach (Requirement tRequirement in t.Requirements)
            {
                Assert.NotNull(tRequirement.CertificateType);
            }
        }
Exemplo n.º 18
0
 public async Task <Models.Task> AddNewTask(Models.Task task)
 {
     return(await _restService.AddNewTask(task));
 }
Exemplo n.º 19
0
 public async Task <int> GetPlannedLaboriousnessWithDescendant(Models.Task task)
 {
     return(await GetPlannedLaboriousnessWithDescendant(task.Id));
 }
Exemplo n.º 20
0
 public async Task <Models.Task> EditTask(Models.Task task)
 {
     return(await _restService.EditTask(task));
 }
Exemplo n.º 21
0
 public IQueryable <Models.Task> GetClosestDescendantTasks(Models.Task task)
 {
     return(GetClosestDescendantTasks(task.Id));
 }