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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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)));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
        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)));
        }
예제 #7
0
        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));
        }
예제 #8
0
        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()));
            }
        }
예제 #9
0
        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());
        }
예제 #10
0
        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());
        }
예제 #12
0
        public async Task <Domain.Task> CreateAsync(TaskUpdateModel task)
        {
            await this.CategoryGetService.ValidateAsync(task);

            return(await this.TaskDataAccess.InsertAsync(task));
        }