示例#1
0
        public async Task <IActionResult> UpdateTaskAsync(TaskForUpdateDto task)
        {
            if (await _taskBLL.UpdateTaskAsync(task))
            {
                return(Ok(true));
            }

            return(BadRequest());
        }
示例#2
0
        public async Task <bool> UpdateTaskAsync(TaskForUpdateDto task)
        {
            MyTask taskForUpdate = await _taskRepo.Queryable().Where(p => p.Id == task.Id).FirstOrDefaultAsync();

            _taskRepo.Update(taskForUpdate);
            bool retVal = await _taskRepo.SaveChangesAsync() > 0;

            return(retVal);
        }
示例#3
0
 public JsonResult UpdateTaskById(int id, TaskForUpdateDto task)
 {
     try
     {
         data.UpdateTaskById(id, task);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(Json(task));
 }
示例#4
0
        public async Task <IActionResult> Put([FromBody] TaskForUpdateDto taskForUpdate)
        {
            var id   = taskForUpdate.TaskId;
            var task = new Domain.Entities.Task()
            {
                // Map the Dto userForUpdate to user by assigning properties
                // Add other members by assigning userIds in the list AssigneeIds of task
            };
            await _unitOfWork.Tasks.UpdateAsync(id, task);

            await _unitOfWork.SaveChangesAsync();

            return(Ok());
        }
示例#5
0
        public async void LogOnUpdateOfEntity_UpdateTask_ShouldReturnUpdatedTaskLog()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase($"TechTaskTestDatabase {Guid.NewGuid()}")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                var taskToAdd = new Tasks
                {
                    AdminApprovalOfTaskCompletion = 0,
                    Balance     = 0,
                    Description = "Test",
                    Name        = "Test name",
                    EstimatedTimeToFinishInHours = 3,
                    Id               = 11,
                    Status           = 0,
                    TaskPriorityId   = 2,
                    TotalHoursOfWork = 0
                };

                context.Tasks.Add(taskToAdd);

                await context.SaveChangesAsync();

                var dbLog = new DbLogService(context);
                await dbLog.LogOnCreationOfEntityAsync(taskToAdd);

                var dto = new TaskForUpdateDto
                {
                    AdminApprovalOfTaskCompletion = 0,
                    Balance     = 0,
                    Description = "Test",
                    Name        = "Test name",
                    EstimatedTimeToFinishInHours = 3,
                    Status         = 0,
                    TaskPriorityId = 2
                };
                dbLog.LogOnUpdateOfAnEntity(taskToAdd);
                await context.SaveChangesAsync();
            }

            using (var context = new AppDbContext(options))
            {
                var logFromDb = await context.UpdateLogs
                                .SingleAsync(u => u.Name == "Updated Task");

                logFromDb.Value.Should().Be(("11").ToLowerInvariant());
            }
        }
示例#6
0
        public async Task <IActionResult> Update(string name, TaskForUpdateDto taskForUpdateDto)
        {
            var taskFromRepo = await _repo.GetTask(name);

            taskForUpdateDto.LastModified = DateTime.Now;

            _mapper.Map(taskForUpdateDto, taskFromRepo);

            if (await _search.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating task {name} failed on save");
        }
示例#7
0
        public async Task <int> UpdateTask(Tasks task, TaskForUpdateDto dto)
        {
            task.Name        = dto.Name ?? task.Name;
            task.Description = dto.Description ?? task.Description;
            task.EstimatedTimeToFinishInHours = dto.EstimatedTimeToFinishInHours ??
                                                task.EstimatedTimeToFinishInHours;
            task.TaskPriorityId = dto.TaskPriorityId ?? task.TaskPriorityId;
            task.Status         = dto.Status ?? task.Status;
            task.Balance        = dto.Balance ?? task.Balance;
            task.AdminApprovalOfTaskCompletion = dto.AdminApprovalOfTaskCompletion ??
                                                 task.AdminApprovalOfTaskCompletion;
            task.TrackerId        = dto.TrackerId ?? task.TrackerId;
            task.TrackerFirstName = dto.TrackerFirstName ?? task.TrackerFirstName;
            task.TrackerLastName  = dto.TrackerLastName ?? task.TrackerLastName;
            task.UserId           = dto.UserId ?? task.UserId;
            _dbLogService.LogOnUpdateOfAnEntity(task);

            return(await _context.SaveChangesAsync());
        }
示例#8
0
        public void UpdateTaskById(int id, TaskForUpdateDto task)
        {
            SqlCommand command = new SqlCommand("update_task", connection)
            {
                CommandType = CommandType.StoredProcedure
            };

            command.Parameters.AddWithValue("@Id", id);

            command.Parameters.AddWithValue("@Description", task.Description);

            command.Parameters.AddWithValue("@Status", task.Status);

            command.Parameters.AddWithValue("@Deadline", task.DeadlineUpdate);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
示例#9
0
        public IActionResult UpdateTask(Guid userId, int taskId, [FromBody] TaskForUpdateDto task)
        {
            try
            {
                if (task == null)
                {
                    _logger.LogError("Task object sent from client is null");
                    return(BadRequest("Task object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid user object sent from client");
                    return(BadRequest("Invalid model object"));
                }

                var taskEntity = _repository.Task.GetTaskById(taskId);

                if (taskEntity == null)
                {
                    _logger.LogError($"Task with id: {taskId}, was not found in database.");
                    return(NotFound());
                }

                if (!taskEntity.UserId.Equals(userId))
                {
                    _logger.LogError($"There is no task with id {taskId} that matches {userId} in database");
                    return(NotFound());
                }

                _mapper.Map(task, taskEntity);

                _repository.Task.UpdateTask(taskEntity);
                _repository.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateTask action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#10
0
        public async Task <IActionResult> UpdateTask(string userName, int id, TaskForUpdateDto taskForUpdate)
        {
            if (userName != (User.FindFirst(ClaimTypes.Name).Value))
            {
                return(Unauthorized());
            }

            var task = await toDoRepository.getToDo(userName, id);

            if (task != null)
            {
                mapper.Map(taskForUpdate, task);

                if (await toDoRepository.SaveAll())
                {
                    return(Ok("Succesfuly updated"));
                }

                return(BadRequest("Dupa"));
            }

            return(NotFound());
        }
示例#11
0
        public async Task <IActionResult> UpdateTaskForProject(Guid projectId, Guid taskId, TaskForUpdateDto taskForUpdate)
        {
            if (taskForUpdate.StartDate < DateTime.Today)
            {
                return(BadRequest("Start Date cannot be before today"));
            }

            if (taskForUpdate.EndDate < taskForUpdate.StartDate)
            {
                return(BadRequest("End Date cannot be before Start Date"));
            }

            var projectFromRepo = await _repository.Project.GetProjectWithUsers(projectId);

            if (projectFromRepo == null)
            {
                return(BadRequest("Project doesn't exist"));
            }

            var taskFromRepo = await _repository.Task.GetTask(taskId);

            if (taskFromRepo == null)
            {
                return(BadRequest("Task does not exist"));
            }

            if (taskForUpdate.AssigneeEmail != null)
            {
                var user = await _repository.User.GetUser(taskForUpdate.AssigneeEmail);

                if (user == null)
                {
                    return(BadRequest("User doesn't exist"));
                }

                var userOnProject = projectFromRepo.Users.FirstOrDefault(up => up.UserId.Equals(user.Id));
                if (userOnProject == null)
                {
                    return(BadRequest("User not on project"));
                }

                taskFromRepo.AssigneeId = user.Id;
            }

            Status     status;
            Priority   priority;
            Completion percentage;

            Enum.TryParse(taskForUpdate.Status, out status);
            Enum.TryParse(taskForUpdate.Percentage, out percentage);
            Enum.TryParse(taskForUpdate.Priority, out priority);

            _mapper.Map(taskForUpdate, taskFromRepo);

            taskFromRepo.Status     = status;
            taskFromRepo.Percentage = percentage;
            taskFromRepo.Priority   = priority;

            _repository.Task.UpdateTask(taskFromRepo);
            var updateTask = await _repository.SaveAsync();

            if (!updateTask)
            {
                throw new Exception("Failed to update task");
            }

            return(NoContent());
        }