Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "list/{listid}/task/{taskid}")] TaskDTO task,
            string listid, string taskid)
        {
            try
            {
                var command = new UpdateTaskCommand
                {
                    ListId      = listid,
                    TaskId      = taskid,
                    Name        = task.Name,
                    Description = task.Description
                };
                var handler = Container.GetInstance <ICommandHander <UpdateTaskCommand> >();

                await handler.Execute(command);

                return(new NoContentResult());
            }
            catch (ResourceNotFoundException ex)
            {
                Container.GetInstance <TelemetryClient>().TrackException(ex);

                return(new NotFoundResult());
            }
            catch (Exception ex)
            {
                Container.GetInstance <TelemetryClient>().TrackException(ex);

                return(new InternalServerErrorResult());
            }
        }
Exemple #2
0
        public static void TaskMapper(this InputModelToDomainMappingProfile profile)
        {
            profile.CreateMap <CreateTaskInputModel, CreateTaskCommand>()
            .ForMember(x => x.Id, opt => opt.Ignore())
            .ForMember(x => x.Status, opt => opt.Ignore())
            .ForMember(x => x.Name, opt => opt.Ignore())
            .ForMember(x => x.ValidationResult, opt => opt.Ignore())
            .ConstructUsing(x => CreateTaskCommand.Create(
                                x.Title,
                                x.Description));

            profile.CreateMap <UpdateTaskInputModel, UpdateTaskCommand>()
            .ForMember(x => x.Name, opt => opt.Ignore())
            .ForMember(x => x.ValidationResult, opt => opt.Ignore())
            .ConstructUsing(x => UpdateTaskCommand.Create(
                                x.Id,
                                x.Title,
                                x.Description,
                                x.Status));

            profile.CreateMap <DeleteTaskInputModel, DeleteTaskCommand>()
            .ForMember(x => x.Title, opt => opt.Ignore())
            .ForMember(x => x.Description, opt => opt.Ignore())
            .ForMember(x => x.Status, opt => opt.Ignore())
            .ForMember(x => x.Name, opt => opt.Ignore())
            .ForMember(x => x.ValidationResult, opt => opt.Ignore())
            .ConstructUsing(x => DeleteTaskCommand.Create(x.id));
        }
Exemple #3
0
        public async Task Execute_ReturnsCompletedTaskOnSuccess()
        {
            var repo   = new Mock <IListRepository>();
            var listId = Guid.NewGuid().ToString();
            var taskId = Guid.NewGuid().ToString();
            var list   = new List
            {
                Id    = listId,
                Tasks = new List <Domain.Task>
                {
                    new Domain.Task
                    {
                        Id = taskId
                    }
                }
            };
            var command = new UpdateTaskCommand {
                ListId = listId, TaskId = taskId
            };
            var handler = new UpdateTaskCommandHandler(repo.Object);

            repo.Setup(r => r.GetById(It.IsAny <string>())).ReturnsAsync(list);

            var result = handler.Execute(command);

            await result;

            Assert.AreEqual(true, result.IsCompleted);
        }
        public async Task <CommandResponse> ExecuteAsync(UpdateTaskCommand command)
        {
            // map task
            TaskDb entityToUpdate = mapper.Map <TaskDb>(command.UpdateTaskDTO);

            // update
            bool   isUpdated = true;
            string message   = "Record updated";

            try
            {
                unitOfWork.Update(entityToUpdate, excludeProperties: $"{nameof(TaskDb.CreatedAt)}");
                await unitOfWork.SaveAsync();
            }
            catch (System.Exception e)
            {
                isUpdated = false;
                message   = Common.Algorithms.GetFullText(e);
            }

            // result
            return(new CommandResponse
            {
                IsSucessed = isUpdated,
                Message = message
            });
        }
Exemple #5
0
        public async System.Threading.Tasks.Task Handle(UpdateTaskCommand message)
        {
            var task = _repository.GetById <OTask>(message.TaskId);

            task.Update(message.Name, message.Priority, message.JobOrderId);
            await _repository.SaveAsync(task);
        }
        public async System.Threading.Tasks.Task ShouldUpdateTask()
        {
            var userId = await RunAsDefaultUserAsync();

            var employeeId = await SendAsync(new CreateEmployeeCommand
            {
                Name = "New Employee"
            });

            var itemId = await SendAsync(new CreateTaskCommand
            {
                EmployeeId = employeeId,
                Title      = "New Task"
            });

            var command = new UpdateTaskCommand
            {
                Id    = itemId,
                Title = "Updated Task"
            };

            await SendAsync(command);

            var item = await FindAsync <Domain.Entities.Task>(itemId);

            item.Title.Should().Be(command.Title);
            item.LastModifiedBy.Should().NotBeNull();
            item.LastModifiedBy.Should().Be(userId);
            item.LastModified.Should().NotBeNull();
            item.LastModified.Should().BeCloseTo(DateTime.Now, 1000);
        }
        public async Task <IActionResult> UpdateAsync([FromBody] UpdateTaskCommand updateCommand)
        {
            if (updateCommand.Id == Guid.Empty)
            {
                return(BadRequest("Id can't be empty."));
            }

            if (updateCommand.ProjectId == Guid.Empty)
            {
                return(BadRequest("Project Id can't be empty."));
            }

            if (string.IsNullOrEmpty(updateCommand.Name))
            {
                return(BadRequest("Name can't be empty."));
            }

            try
            {
                var result = await _mediator.Send(updateCommand);

                return(Ok(result));
            }
            catch (DataNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #8
0
        public async Task Should_update_status_to_done(TaskType taskType)
        {
            const string body      = "Automated Test Complete Task";
            const string updatedBy = "*****@*****.**";

            _newConferenceId = Guid.NewGuid();
            var task = new Alert(_newConferenceId, _newConferenceId, body, taskType);
            await TestDataManager.SeedAlerts(new List <Alert> {
                task
            });

            var command = new UpdateTaskCommand(_newConferenceId, task.Id, updatedBy);
            await _handler.Handle(command);

            List <Alert> alerts;

            await using (var db = new VideoApiDbContext(VideoBookingsDbContextOptions))
            {
                alerts = await db.Tasks.Where(x => x.ConferenceId == command.ConferenceId).ToListAsync();
            }

            var updatedAlert = alerts.First(x => x.Id == task.Id);

            updatedAlert.Should().NotBeNull();
            updatedAlert.Status.Should().Be(TaskStatus.Done);
            updatedAlert.Updated.Should().NotBeNull();
            updatedAlert.UpdatedBy.Should().Be(updatedBy);
        }
Exemple #9
0
        public void QueueAddOrSaveTask(TaskInputModel input)
        {
            Command command;
            var     isNewTask = (input.TaskId == Guid.Empty);

            if (isNewTask)
            {
                command = new AddNewTaskCommand(
                    input.Title,
                    input.Description,
                    input.DueDate,
                    input.Priority,
                    input.SignalrConnectionId);
            }
            else
            {
                command = new UpdateTaskCommand(
                    input.TaskId,
                    input.Title,
                    input.Description,
                    input.DueDate,
                    input.Priority,
                    input.Status,
                    input.SignalrConnectionId);
            }

            Bus.Send(command);
        }
Exemple #10
0
        public async Task <IActionResult> UpdateTaskStatusAsync(Guid conferenceId, long taskId,
                                                                [FromBody] UpdateTaskRequest updateTaskRequest)
        {
            _logger.LogDebug("UpdateTaskStatus");
            try
            {
                var command = new UpdateTaskCommand(conferenceId, taskId, updateTaskRequest.UpdatedBy);
                await _commandHandler.Handle(command);
            }
            catch (TaskNotFoundException ex)
            {
                _logger.LogError(ex, "Unable to find task");
                return(NotFound());
            }

            var query = new GetTasksForConferenceQuery(conferenceId);
            var tasks = await _queryHandler.Handle <GetTasksForConferenceQuery, List <Task> >(query);

            var task = tasks.SingleOrDefault(x => x.Id == taskId);

            if (task == null)
            {
                _logger.LogError("Unable to find task");
                return(NotFound());
            }
            var response = TaskToResponseMapper.MapTaskToResponse(task);

            return(Ok(response));
        }
Exemple #11
0
        public async Task HandleInvokesUpdateTaskAsyncWithCorrectData()
        {
            var options = this.CreateNewContextOptions();

            const int taskId  = 1;
            var       message = new UpdateTaskCommand {
                AllReadyTask = new AllReadyTask {
                    Id = taskId
                }
            };

            using (var context = new AllReadyContext(options)) {
                context.Tasks.Add(new AllReadyTask {
                    Id             = taskId,
                    RequiredSkills = new List <TaskSkill> {
                        new TaskSkill()
                    }
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new UpdateTaskCommandHandler(context);
                await sut.Handle(message);
            }

            using (var context = new AllReadyContext(options)) {
                var @task = context.Tasks.Include(t => t.RequiredSkills).FirstOrDefault(t => t.Id == taskId);
                Assert.NotNull(@task);
                Assert.Equal(@task.RequiredSkills.Count, 0);
            }
        }
 public GenericCommandResult Update(
     [FromBody] UpdateTaskCommand command,
     [FromServices] TaskHandler handler
     )
 {
     command.User = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;
     return((GenericCommandResult)handler.Handle(command));
 }
        public Task Update(UpdateTaskCommand command)
        {
            var task = _repository.GetById(command.Id);

            task.Update(command.Title);
            _repository.Update(task);
            return(task);
        }
        public async Task <IActionResult> UpdateTask([FromBody]  UpdateTaskCommand command)
        {
            if (command is null)
            {
                return(BadRequest());
            }

            return(Json(await _mediator.Send(command)));
        }
Exemple #15
0
 private static void PopulateUpdateCommand(UpdateTaskCommand model, MySqlCommand command)
 {
     command.Parameters.Add("@projectId", MySqlDbType.Int32).Value     = model.ProjectId;
     command.Parameters.Add("@requirementId", MySqlDbType.Int32).Value = model.RequirementId;
     command.Parameters.Add("@taskId", MySqlDbType.Int32).Value        = model.Id;
     command.Parameters.Add("@name", MySqlDbType.VarChar).Value        = model.Name;
     command.Parameters.Add("@description", MySqlDbType.VarChar).Value = model.Description;
     command.Parameters.Add("@stage", MySqlDbType.Int32).Value         = model.Stage;
 }
Exemple #16
0
        public void TestInitialize()
        {
            var commandFactory = AssemblyConfiguration.Kernel.Get <CommandFactory>();
            var queryFactory   = AssemblyConfiguration.Kernel.Get <QueryFactory>();

            _mapper            = AssemblyConfiguration.Kernel.Get <IMapper>();
            _createTaskCommand = commandFactory.GetInstance <CreateTaskCommand>();
            _getTaskQuery      = queryFactory.GetInstance <GetTasksQuery>();
            _sut = commandFactory.GetInstance <UpdateTaskCommand>();
        }
Exemple #17
0
        public void Should_throw_task_not_found_exception()
        {
            const string updatedBy = "*****@*****.**";

            _newConferenceId = Guid.NewGuid();

            var command = new UpdateTaskCommand(_newConferenceId, 9999, updatedBy);

            Assert.ThrowsAsync <TaskNotFoundException>(() => _handler.Handle(command));
        }
        public ActionResult Put(UpdateTaskCommand command)
        {
            var userId = User.Identity.GetUserId();

            command.UserId = userId;
            PipelineService.HandleCommand(command);
            var data = PipelineService.Query <TasksQueries>().With(q => q.GetByIdDto(command.Id));

            return(Json(data));
        }
        public static UpdateTaskCommand ToUpdateTaskCommand(this TaskVm model)
        {
            var command = new UpdateTaskCommand()
            {
                Id               = model.Id,
                IsComplete       = model.IsComplete,
                AssignedMemberId = model.AssignedMemberId
            };

            return(command);
        }
        public async Task <ActionResult> Update(int id, UpdateTaskCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
        public void ShouldRequireValidTaskId()
        {
            var command = new UpdateTaskCommand
            {
                Id    = 99,
                Title = "Updated Task"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
        //[ProducesResponseType(451)]  ?xD
        public async Task <IActionResult> UpdateTask([FromBody] UpdateTaskCommand command)
        {
            var response = await mediator.Send(command);

            if (response.IsSuccess)
            {
                return(Ok());
            }

            return(StatusCode(500, response.Error));
        }
Exemple #23
0
        public async Task <IActionResult> UpdateTaskAsync(int id, [FromBody] UpdateTaskCommand command)
        {
            command.Id = id;
            var response = await CommandAsync(command);

            if (response.Errors.Any())
            {
                return(BadRequest(response.Errors));
            }

            return(Ok(response.Result));
        }
Exemple #24
0
        public void Update(Guid taskId, string taskName, global::Merp.TimeTracking.TaskManagement.QueryStack.Model.TaskPriority priority, Guid?jobOrderId)
        {
            var cmd = new UpdateTaskCommand(
                taskId: taskId,
                userId: GetCurrentUserId(),
                name: taskName,
                priority: priority.Convert(),
                jobOrderId: jobOrderId
                );

            Bus.Send(cmd);
        }
Exemple #25
0
        public static UpdateTaskCommand ToUpdateTaskCommand(this TaskVm model)
        {
            var command = new UpdateTaskCommand()
            {
                Id     = model.Id,
                Member = model.Member,
                Text   = model.Text,
                IsDone = model.IsDone
            };

            return(command);
        }
        public static UpdateTaskCommand ToUpdateTaskCommand(this TaskVm model)
        {
            var command = new UpdateTaskCommand()
            {
                Id           = model.Id,
                Subject      = model.Subject,
                AssignedToId = model.AssignedToId,
                IsComplete   = model.IsComplete
            };

            return(command);
        }
        public void Update(Guid taskId, UpdateModel model)
        {
            var cmd = new UpdateTaskCommand(
                taskId: taskId,
                userId: GetCurrentUserId(),
                name: model.Name,
                priority: model.Priority.Convert(),
                jobOrderId: model.JobOrderId
                );

            Bus.Send(cmd);
        }
        public async Task <IActionResult> Update(Guid id, UpdateTaskCommand command)
        {
            try
            {
                var result = await _taskService.UpdateTaskCommandHandler(command);

                return(Ok(result));
            }
            catch (NotFoundException <Guid> )
            {
                return(NotFound());
            }
        }
        public async Task <UpdateTaskCommandResult> UpdateTaskCommandHandler(UpdateTaskCommand command)
        {
            var member = await _taskRepository.ByIdAsync(command.Id);

            _mapper.Map(command, member);

            var affectedRecordsCount = await _taskRepository.UpdateRecordAsync(member);

            return(new UpdateTaskCommandResult()
            {
                Succeeded = affectedRecordsCount < 1
            });
        }
        public async Task <ActionResult> Update([FromBody] UpdateTaskCommand updateTaskCommand)
        {
            try
            {
                await Mediator.Send(updateTaskCommand);

                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }