public void TestTask(TaskModel testTask) { string message = string.Empty; ProjectController projectController = new ProjectController(); ProjectUpdateModel projectResult = new ProjectUpdateModel(); UserUpdateModel userResult = AddEditUser(); ProjectModel testProject = GetTestProject(); TaskController taskc = new TaskController(); TaskUpdateModel tresult = new TaskUpdateModel(); testProject.Manager_ID = userResult.user.User_ID; testProject.Manager_Name = userResult.user.First_Name + userResult.user.Last_Name; projectResult = projectController.Post(testProject); message = projectResult.status.Message; Assert.AreEqual(NEW_PROJECT_SUCCESS, message); testTask.Project_ID = projectResult.project.Project_ID; testTask.Project_Name = projectResult.project.ProjectName; testTask.User_ID = userResult.user.User_ID; testTask.Task_ID = 0; tresult = taskc.Post(testTask); Assert.AreEqual(NEW_TASK_SUCCESS, tresult.status.Message); TaskModel tasks = taskc.Get().Where(x => x.TaskName == testTask.TaskName).FirstOrDefault(); tresult = taskc.Post(tasks); Assert.AreEqual(UPDATE_TASK_SUCCESS, tresult.status.Message); }
public async Task CreateAsync_DepartmentValidationFailed_ThrowsError() { // Arrange var fixture = new Fixture(); var task = new TaskUpdateModel(); var expected = fixture.Create <string>(); var categoryGetService = new Mock <ICategoryGetService>(); categoryGetService .Setup(x => x.ValidateAsync(task)) .Throws(new InvalidOperationException(expected)); var taskDataAccess = new Mock <ITaskDataAccess>(); var taskGetService = new TaskCreateService(taskDataAccess.Object, categoryGetService.Object); // Act var action = new Func <Task>(() => taskGetService.CreateAsync(task)); // Assert await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected); taskDataAccess.Verify(x => x.InsertAsync(task), Times.Never); }
public IActionResult Update([FromRoute] int taskId, TaskUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest()); } if (!_taskRepository.Find(x => x.UserId == UserId && x.TaskId == taskId).Any()) { return(Forbid()); } var task = _taskRepository.Find(x => x.TaskId == taskId).FirstOrDefault(); if (task == null) { return(NotFound()); } task.NumberTransactions = model.NumberTransactions; var result = _taskRepository.Update(task); return(Ok(_mapper.Map <TaskModel>(result))); }
public async Task <IActionResult> Edit(TaskUpdateModel model) { try { if (ModelState.IsValid) { var newTaskId = await _mediator.Send(new UpdateTaskCommand() { Id = model.CurrentName, Name = model.Name, Priority = model.Priority, Status = model.StatusCode }); return(RedirectToAction("Index")); } } catch (NotFoundException) { return(NotFound()); // TODO: global handlers for 404, 500 } catch (AppException ex) { ModelState.AddModelError("app_error", ex.Message); } model.AvailableStatusses = AvailableStatusses; return(View(model)); }
public async Task <Domain.Task> InsertAsync(TaskUpdateModel Task) { var result = await this.Context.AddAsync(this.Mapper.Map <Domain.Task>(Task)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Domain.Task>(result.Entity)); }
public ActionResult <TaskModel> UpdateTask([FromBody] TaskUpdateModel model) { var data = new TaskModel() { Id = model.Id, TaskName = model.TaskName, Status = model.Status }; return(Ok(taskService.UpdateTask(data))); }
public async Task <Domain.Task> UpdateAsync(TaskUpdateModel Task) { var existing = await this.Get(Task); var result = this.Mapper.Map(Task, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Domain.Task>(result)); }
public async Task <IActionResult> Update([FromBody] TaskUpdateModel value) { if (value == null) { return(NotFound()); } var userDto = mapper.Map <TaskDto>(value); var result = await service.UpdateAsync(userDto); if (result.IsSuccess) { return(Ok()); } else { return(new JsonResult(result.GetErrorString())); } }
public IActionResult UpdateTask([FromBody] TaskUpdateModel data) { var day = _dbContext.Days.Include(x => x.Competition).FirstOrDefault(x => x.Id == data.DayId); if (day == null) { return(BadRequest()); } if (!User.IsAdminUser(day.Competition, _dbContext)) { return(BadRequest()); } day.Task = data.Task.ToXml(); _dbContext.SaveChanges(); return(Ok()); }
public async Task CreateAsync_DepartmentValidationSucceed_CreatesTask() { // Arrange var task = new TaskUpdateModel(); var expected = new Domain.Task(); var categoryGetService = new Mock <ICategoryGetService>(); categoryGetService.Setup(x => x.ValidateAsync(task)); var taskDataAccess = new Mock <ITaskDataAccess>(); taskDataAccess.Setup(x => x.InsertAsync(task)).ReturnsAsync(expected); var taskGetService = new TaskCreateService(taskDataAccess.Object, categoryGetService.Object); // Act var result = await taskGetService.CreateAsync(task); // Assert result.Should().Be(expected); }
public IActionResult UpdateTask(Guid id, [FromBody] TaskUpdateModel task) { if (task == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingTask = _taskSevice.GetTask(id); if (existingTask == null) { return(NotFound($"The task with id : {id} was not found.")); } _taskSevice.UpdateTask(id, task.TaskName, task.TaskDescription, task.TaskDateTime, task.TaskPriority); return(NoContent()); }
public async Task <Domain.Task> CreateAsync(TaskUpdateModel task) { await this.CategoryGetService.ValidateAsync(task); return(await this.TaskDataAccess.InsertAsync(task)); }