public IActionResult Put(int id, [FromBody] Task value) { if (value.TaskId != id) { return(BadRequest("Identifier doesnt match")); } if (ModelState.IsValid) { try { return(Ok(taskLogic.UpdateTask(id, value))); } catch (Exception ex) { _logger.LogError(ex, $"Error during Updating Task by Id - {id} with new values: {value.Stringify()}"); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } } else { _logger.LogWarning("Invalid/Incomplete Task Information - {0}", value.Stringify()); return(BadRequest(ModelState)); //"Invalid request information. Please verify the information entered.", } }
public IActionResult UpdateTask([FromBody] CreateTaskRequest request) { var task = _taskLogic.UpdateTask(request); if (task) { return(Ok()); } return(NotFound()); }
public void Test_For_EditTask(int testTaskIdForEdit, bool expectedExistsResult, bool expectedUpdateResult) { // Arrange var userGuid = Guid.NewGuid(); Models.DataModels.Task testTaskForEdit; if (expectedExistsResult || expectedUpdateResult) { testTaskForEdit = new Models.DataModels.Task() { TaskId = testTaskIdForEdit, TaskName = "TestTask" + testTaskIdForEdit, Priority = 20, ProjectId = 100, TaskOwnerId = userGuid, StartDate = DateTime.Today, Project = new Models.DataModels.Project() { ProjectId = 100, ProjectName = "TestProject-XY", Priority = 1, ManagerId = userGuid }, TaskOwner = new Models.DataModels.User() { Id = userGuid, UserId = "TestUser1", FirstName = "First", LastName = "Last" } }; } else { testTaskForEdit = null; } mockTaskRepo.Setup(repo => repo.GetById(testTaskIdForEdit)).Returns(testTaskForEdit); mockTaskRepo.Setup(repo => repo.Update(It.IsAny <Models.DataModels.Task>())).Returns(expectedUpdateResult); // Act var actualResult = tasksLogicTest.UpdateTask(testTaskIdForEdit, testTaskForEdit.AsViewModel()); // Assert Assert.Equal(expectedUpdateResult, actualResult); }