Esempio n. 1
0
        public async Task EditProjectTest()
        {
            _mediator.Setup(m => m.Send(It.IsAny <EditProjectCommand>(), new System.Threading.CancellationToken()))
            .Returns(Task.FromResult(new Core.ApiResponse.ApiResult
            {
                Code = Code.Ok
            }));

            _authorizationService.Setup(g => g.GetUser())
            .Returns(new Core.DataStructure.ControllerUser
            {
                UserName = "******",
                UserId   = 1234
            });

            var command = new EditProjectCommand
            {
                Id          = 1,
                ProjectName = "测试标题",
                Desc        = "测试描述",
                Platform    = "github"
            };

            var controller = new ProjectController(_mediator.Object, _log.Object, _authorizationService.Object, _projectQueries.Object);
            var result     = await controller.EditProjectAsync(command);

            Assert.NotNull(result);
            Assert.Equal(Code.Ok, result.Code);
        }
Esempio n. 2
0
        protected override void Initialize()
        {
            base.Initialize();

            DTE            = GetService(typeof(EnvDTE.DTE)) as DTE2;
            CommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            EditProjectCommand.Initialize(this);
            EditProjectsCommand.Initialize(this);
        }
Esempio n. 3
0
        public ActionResult Edit(int projectId, EditProjectViewModelPost edit)
        {
            Request.ThrowIfDifferentReferrer();

            var project = _database.Projects
                          .FilterById(projectId)
                          .AsDbQuery()
                          .Include(p => p.Owner)
                          .SingleOrDefault();

            var currentUser = _userManager.FindById(User.Identity.GetUserId());

            if (project != null && currentUser != null &&
                (project.Owner == currentUser || User.IsInRole(UserRoles.ADMIN)))
            {
                if (ModelState.IsValid &&
                    PathNameValidation.CheckContainsNoForbiddenPathCharacters(ModelState, nameof(edit.Name), edit.Name) &&
                    CheckProjectNameAlreadyInUse(nameof(edit.Name), edit.Name, project.Owner, project.Id) &&
                    SessionDefinitionValidation.CheckDefinitionTemplateJson(ModelState, nameof(edit.SessionDefinitionTemplate), edit.SessionDefinitionTemplate))
                {
                    string nameBeforeEdit = project.Name;

                    var command = new EditProjectCommand()
                    {
                        Project     = project,
                        Name        = edit.Name,
                        Description = edit.Description,
                        SessionDefinitionTemplate = edit.SessionDefinitionTemplate
                    };

                    _dispatcher.Dispatch(command);

                    if (project.Name != nameBeforeEdit)
                    {
                        _recordings.UpdateProjectDataLocation(project, nameBeforeEdit);
                    }

                    return(RedirectToAction(nameof(Details), new { projectId = project.Id }));
                }

                var newEdit = Mapper.Map <EditProjectViewModel>(edit);

                newEdit.OriginalName = project.Name;
                newEdit.SessionDefinitionTemplates = GetSessionTemplatesList();

                return(View(newEdit));
            }

            return(HttpNotFound());
        }
Esempio n. 4
0
 public void Edit(EditProjectCommand command)
 {
     _db.Connection().Execute(
         "spEditProject",
         new
     {
         id          = command.Id,
         title       = command.Title,
         description = command.Description,
         updatedAt   = command.UpdatedAt,
         ownerId     = command.OwnerId,
         status      = command.Status
     },
         commandType: CommandType.StoredProcedure
         );
 }
Esempio n. 5
0
        public async Task <ApiResult> EditProjectAsync([FromBody] EditProjectCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(InValidModelsError());
            }
            var user = _authorizationService.GetUser();

            if (user == null)
            {
                return(AuthorizeError());
            }

            _log.LogInformation("执行EditProjectAsync...控制器方法");

            return(await _mediator.Send(command));
        }
        public ICommandResult Handle(EditProjectCommand command)
        {
            var owner     = _repository.GetOwner(command.OwnerId);
            var ownerName = new Name(owner.FirstName, owner.LastName);
            var user      = new User(owner.OwnerId, ownerName, owner.Status);
            var project   = new Project(command.Title, command.Description, DateTime.Now, user, command.Status);

            AddNotifications(ownerName.Notifications);
            AddNotifications(user.Notifications);
            AddNotifications(project.Notifications);

            if (Invalid)
            {
                return(new CommandResult(MessagesUtil.EditedError, false, Notifications));
            }
            if (user.Status == EUserStatus.Inactive)
            {
                return(new CommandResult(MessagesUtil.UserInactive, false));
            }

            _repository.Edit(command);
            return(new CommandResult(MessagesUtil.EditedSuccess, true));
        }
Esempio n. 7
0
        //===

        private void InstantiateProjectCommands()
        {
            EditProjectCommand.Instantiate(this);
        }
Esempio n. 8
0
 private async Tasks.Task InstantiateProjectCommandsAsync()
 {
     await EditProjectCommand.InstantiateAsync(this);
 }
Esempio n. 9
0
        public ActionResult SubmitEdit(EditProjectCommand command)
        {
            _editProjectHandler.Handle(command);

            return(RedirectToAction("Index", "Project", new { area = "Admin" }));
        }
Esempio n. 10
0
        public async Task <IActionResult> EditProject(EditProjectCommand request)
        {
            await _mediator.Send(request);

            return(Ok());
        }
 public ICommandResult Put([FromBody] EditProjectCommand command)
 {
     return(_handler.Handle(command));
 }
 public void Edit(EditProjectCommand command)
 {
 }