public async Task <JsonResult> GetNewTaskItem(TaskItemModel model) { try { TaskItemDto dto = _mapper.Map <TaskItemDto>(model); dto = await _taskItemService.GetNewTask(dto); dto.TaskItemAssigns.Add(new TaskItemAssignDto { AssignToFullName = CurrentUser.FullName, AssignToJobTitleName = CurrentUser.Departments != null ? CurrentUser.Departments[0].JobTitle : string.Empty, Department = CurrentUser.Departments != null ? CurrentUser.Departments[0].Name : string.Empty, AssignTo = CurrentUser.Id, TaskType = Entities.TaskType.Primary }); dto.AssignBy = CurrentUser.Id; dto.AssignByFullName = CurrentUser.FullName; model = _mapper.Map <TaskItemModel>(dto); model.TaskItemAssignIds = model.TaskItemAssigns.Select(e => e.AssignTo).ToList(); } catch (Exception ex) { _loggerServices.WriteError(ex.ToString()); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> UpdateTaskItem(string boardId, TaskItemDto item) { item.TaskBoardId = boardId; await _taskBoardService.UpdateTaskAsync(item); return(Json(new { message = "Task Updated successfully" })); }
public IHttpActionResult PutTaskItem(long id, TaskItemDto taskItemDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != taskItemDto.TaskId) { return(BadRequest()); } var currentUserId = GetCurrentUserId(); var nullCheck = _bl.GetTaskItem(currentUserId, id); if (nullCheck == null) { return(NotFound()); } if (currentUserId != taskItemDto.UserId) { return(Unauthorized()); } _bl.PutTaskItem(taskItemDto); return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Update(long id, [FromBody] TaskItemDto item) { if (item == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_taskRepository.Exists(id)) { return(NotFound()); } var taskItem = _taskRepository.Find(id); taskItem.UpdateFrom(item); if (!_taskRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }
public async Task CreateReturnsBadRequestForNoName() { var taskItem = new TaskItemDto { IsComplete = false }; var response = await _client.PostAsJsonAsync("api/tasks", taskItem); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public void CreateReturnsCreatedAtRouteStatus() { var controller = CreateTaskController("CreateReturnsCreatedAtRouteStatus"); var taskItem = new TaskItemDto { Name = "NewTask", IsComplete = false }; var createResult = controller.Create(taskItem); Assert.IsType <CreatedAtRouteResult>(createResult); }
public void UpdateReturnsBadRequestForInvalidId() { var controller = CreateTaskController("UpdateReturnsBadRequestForInvalidId"); var taskItem = new TaskItemDto { Name = "NewTask", IsComplete = false }; var updateResult = controller.Update(1, taskItem); Assert.IsType <NotFoundResult>(updateResult); }
public async Task <IActionResult> OppositeMark([FromBody] TaskItemDto task) { //var item = _mapper.Map<TaskItem>(task); var updItem = _db.Tasks.Find(task.TaskId); updItem.IsDone = task.IsDone; _db.Tasks.Update(updItem); await _db.SaveChangesAsync(); return(Ok()); }
public void UpdateReturnsNoContentStatus() { var controller = CreateTaskController("UpdateReturnsNoContentStatus"); var taskItem = new TaskItemDto { Name = "NewTask", IsComplete = false }; var id = GetTaskIdForTask(controller, _testData[3].Name); var updateResult = controller.Update(id, taskItem); Assert.IsType <NoContentResult>(updateResult); }
public void CreateAddsTaskToTaskList() { var controller = CreateTaskController("CreateAddsTaskToTaskList"); var taskItem = new TaskItemDto { Name = "NewTask", IsComplete = false }; controller.Create(taskItem); var tasks = GetAllTasks(controller); Assert.Equal(5, tasks.Count()); }
public async Task CreateReturnsProperErrorMessageForEmptyName() { var taskItem = new TaskItemDto { Name = string.Empty, IsComplete = false }; var response = await _client.PostAsJsonAsync("api/tasks", taskItem); var returnMessage = response.Content.ReadAsStringAsync().Result; var expectedMessage = new TaskItemDtoValidator().Validate(taskItem).Errors[0].ErrorMessage; Assert.Contains(expectedMessage, returnMessage); }
public async Task <ActionResult <TaskItemDto> > CreateTask(int projectId, TaskItemDto newTaskItem) { var newTask = _mapper.Map <TaskItem>(newTaskItem); var project = await _projectService.GetProjectById(projectId, false); if (await _taskService.CreateTask(project, newTask)) { var location = _linkGenerator.GetPathByAction("GetProjectById", "Projects", new { id = project.Id }); return(Created(location, _mapper.Map <ProjectDto>(newTask))); } return(BadRequest("Could not create that task.")); }
public async Task <JsonResult> SaveTaskItem(TaskItemModel model) { _loggerServices.WriteError("test log"); SendMessageResponse rs = null; try { TaskItemDto dto = new TaskItemDto(); //check permission dto = _mapper.Map <TaskItemDto>(model); dto.IsFullControl = false; if (CurrentUser.HavePermission(EnumModulePermission.Task_FullControl)) { dto.IsFullControl = true; } dto.ModifiedBy = CurrentUser.Id; dto.ModifiedDate = DateTime.Now; dto.Attachments = new List <AttachmentDto>(); if (Request.Files.Count > 0) { foreach (string file in Request.Files) { var fileContent = Request.Files[file]; byte[] document = Utility.ReadAllBytes(fileContent); string ext = Path.GetExtension(fileContent.FileName).Replace(".", ""); AttachmentDto attachmentDto = new AttachmentDto() { Id = Guid.NewGuid(), CreateByFullName = CurrentUser.FullName, CreatedBy = CurrentUser.Id, CreatedDate = DateTime.Now, FileExt = ext, FileContent = document, FileName = fileContent.FileName, FileSize = fileContent.ContentLength, ProjectId = dto.Id, Source = Entities.Source.TaskItem, }; dto.Attachments.Add(attachmentDto); } } rs = await _taskItemService.SaveAsync(dto); } catch (Exception ex) { _loggerServices.WriteError(ex.ToString()); } return(Json(rs, JsonRequestBehavior.AllowGet)); }
public void CreateReturnsExpectedValueInCreatedAtRouteStatus() { var controller = CreateTaskController("CreateReturnsExpectedValueInCreatedAtRouteStatus"); var taskItem = new TaskItemDto { Name = "NewTask", IsComplete = false }; var createResult = controller.Create(taskItem) as CreatedAtRouteResult; var createdTask = createResult.Value as TaskItem; Assert.Equal(taskItem.Name, createdTask.Name); Assert.Equal(taskItem.IsComplete, createdTask.IsComplete); }
public async Task <IActionResult> Add([FromBody] TaskItemDto task) { ApplicationUser user = await GetCurrentUserAsync(); TaskItem ts = new TaskItem { Name = task.Name, Description = task.Description, IsDone = false, DeadLine = task.DeadLine, User = user }; TagFilter(ts, task.Tags); _db.Tasks.Add(ts); await _db.SaveChangesAsync(); return(Ok()); }
public IHttpActionResult PostTaskItem(TaskItemDto taskItemDto) { taskItemDto.UserId = GetCurrentUserId(); //ModelState["taskItemDto.UserId"].Errors.Clear(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var taskId = _bl.PostTaskItem(taskItemDto); //todo get id logic return(CreatedAtRoute("DefaultApi", taskId, taskItemDto)); }
public void UpdateCorrectlyModifiesTask() { string newName = "NewName"; var controller = CreateTaskController("UpdateCorrectlyModifiesTask"); var taskItem = new TaskItemDto { Name = newName }; var id = GetTaskIdForTask(controller, _testData[3].Name); controller.Update(id, taskItem); var updatedTaskItem = GetTaskById(controller, id); Assert.Equal(newName, updatedTaskItem.Name); }
public async Task <IActionResult> Update([FromBody] TaskItemDto task) { TaskItem updItem = _db.Tasks.Include(t => t.TaskTags).ThenInclude(t => t.Tag).First(t => t.TaskId == task.TaskId); // update user properties updItem.Name = task.Name; updItem.Description = task.Description; updItem.IsDone = task.IsDone; updItem.DeadLine = task.DeadLine; //_db.TaskTag.RemoveRange(_db.TaskTag.Where(t => t.TaskId == task.TaskId)); TagFilter(updItem, task.Tags); //_db.Tasks.Update(updItem); await _db.SaveChangesAsync(); return(Ok()); }
public long?PostTaskItem(TaskItemDto taskItemDto) { var taskItem = _mapper.Map <TaskItemDto, TaskItem>(taskItemDto); taskItem.CreatedDate = DateTime.Now; //Set Created Date try { _uoWork.Tasks.Add(taskItem); _uoWork.Complete(); return(null); } catch (Exception e) { return(null); } }
public HttpStatusCode PutTaskItem(TaskItemDto taskItemDto) { try { var taskItem = _uoWork.Tasks.Get((long)taskItemDto.TaskId); taskItemDto.CreatedDate = taskItem.CreatedDate; //Reset to orginal value. taskItemDto.ModifiedDate = DateTime.Now; //Set Modified Date taskItem = _mapper.Map(taskItemDto, taskItem); _uoWork.Tasks.Update(taskItem); _uoWork.Complete(); return(HttpStatusCode.NoContent); //No Content } catch (Exception e) { //todo implement logger return(HttpStatusCode.InternalServerError); } }
public async Task <JsonResult> GetTaskItem(Guid?id) { TaskItemModel model = new TaskItemModel(); try { TaskItemDto dto = null; if (id.HasValue) { dto = await _taskItemService.GetById(id.Value); if (dto == null) { var rs = SendMessageResponse.CreateFailedResponse("NotExist"); return(Json(rs, JsonRequestBehavior.AllowGet)); } if (dto.CreatedBy != CurrentUser.Id && !CurrentUser.HavePermission(EnumModulePermission.Task_FullControl)) { var rs = SendMessageResponse.CreateFailedResponse("AccessDenied"); return(Json(rs, JsonRequestBehavior.AllowGet)); } } else { dto = new TaskItemDto { AssignBy = CurrentUser.Id, AssignByFullName = CurrentUser.FullName }; dto.TaskItemAssigns.Add(new TaskItemAssignDto { AssignToFullName = CurrentUser.FullName, AssignToJobTitleName = CurrentUser.Departments != null ? CurrentUser.Departments[0].JobTitle : string.Empty, Department = CurrentUser.Departments != null ? CurrentUser.Departments[0].Name : string.Empty, AssignTo = CurrentUser.Id, TaskType = Entities.TaskType.Primary }); } model = _mapper.Map <TaskItemModel>(dto); } catch (Exception ex) { _loggerServices.WriteError(ex.ToString()); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public IActionResult Create([FromBody] TaskItemDto item) { if (item == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var taskItem = new TaskItem(item); _taskRepository.Add(taskItem); if (!_taskRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(CreatedAtRoute("GetTask", new { id = taskItem.Id }, taskItem)); }
public async Task <IActionResult> UpdateTask(int projectId, TaskItemDto updatedTask) { var project = await _projectService.GetProjectById(projectId, true); if (project == null) { return(NotFound("Project with that Id not found.")); } var oldTask = project.Tasks.Where(t => t.Id == updatedTask.Id).Single(); if (oldTask == null) { return(NotFound("Task in the project with the specified Id not found.")); } if (await _taskService.UpdateTask(_mapper.Map <TaskItem>(oldTask), _mapper.Map <TaskItem>(updatedTask))) { return(Ok()); } return(BadRequest("Could not delete that project.")); }
public async Task <JsonResult> UpdateStatusTaskItem(TaskItemModel model) { SendMessageResponse rs = null; try { TaskItemDto dto = new TaskItemDto(); dto = _mapper.Map <TaskItemDto>(model); dto.IsFullControl = false; if (CurrentUser.HavePermission(EnumModulePermission.Task_FullControl)) { dto.IsFullControl = true; } dto.ModifiedBy = CurrentUser.Id; dto.ModifiedDate = DateTime.Now; rs = await _taskItemService.UpdateStatusTaskItem(dto); } catch (Exception ex) { _loggerServices.WriteError(ex.ToString()); } return(Json(rs, JsonRequestBehavior.AllowGet)); }
public TaskItemDeletedEvent(TaskItemDto item) { Item = item; }
public TaskItemUpdatedEvent(TaskItemDto item) { Item = item; }
public TaskItem(TaskItemDto taskItemDto) { Name = taskItemDto.Name; IsComplete = taskItemDto.IsComplete; }
public TaskItemAddedEvent(TaskItemDto item) { Item = item; }
public UpdateTaskItemCommand(TaskItemDto item) { Item = item; }
public void UpdateFrom(TaskItemDto otherItem) { Name = otherItem.Name; IsComplete = otherItem.IsComplete; }