Exemple #1
0
        public CommandFactory(IPersister persister, ISecurityManager security, IVersionManager versionMaker, IEditUrlManager editUrlManager, IContentAdapterProvider adapters, StateChanger changer)
        {
            //this.persister = persister;
            //makeVersionOfMaster = On.Master(new MakeVersionCommand(versionMaker));
            //showEdit = new RedirectToEditCommand(editUrlManager);
            //clone = new CloneCommand();
            //unpublishedDate = new EnsureNotPublishedCommand(); // moved to StateChanger
            //ensurePublishedDate = new EnsurePublishedCommand();  // moved to StateChanger

            this.security = security;

            save   = new SaveCommand(persister);
            delete = new DeleteCommand(persister.Repository);

            replaceMaster     = new ReplaceMasterCommand(versionMaker);
            makeVersion       = new MakeVersionCommand(versionMaker);
            useDraftCmd       = new UseDraftCommand(versionMaker);
            saveOnPageVersion = new SaveOnPageVersionCommand(versionMaker);

            draftState     = new UpdateContentStateCommand(changer, ContentState.Draft);
            publishedState = new UpdateContentStateCommand(changer, ContentState.Published);

            updateObject      = new UpdateObjectCommand();
            useMaster         = new UseMasterCommand();
            validate          = new ValidateCommand();
            saveActiveContent = new ActiveContentSaveCommand();
            moveToPosition    = new MoveToPositionCommand();
            updateReferences  = new UpdateReferencesCommand();
        }
Exemple #2
0
        public CommandFactory(IPersister persister, ISecurityManager security, IVersionManager versionMaker, IEditUrlManager editUrlManager, IContentAdapterProvider adapters, StateChanger changer)
        {
            this.persister = persister;
            makeVersionOfMaster = On.Master(new MakeVersionCommand(versionMaker));
            replaceMaster = new ReplaceMasterCommand(versionMaker);
            makeVersion = new MakeVersionCommand(versionMaker);
            useNewVersion = new UseNewVersionCommand(versionMaker);
            updateObject = new UpdateObjectCommand();
            delete = new DeleteCommand(persister.Repository);
            showPreview = new RedirectToPreviewCommand(adapters);
            showEdit = new RedirectToEditCommand(editUrlManager);
            useMaster = new UseMasterCommand();
            clone = new CloneCommand();
            validate = new ValidateCommand();
            this.security = security;
            save = new SaveCommand(persister);
            incrementVersionIndex = new IncrementVersionIndexCommand(versionMaker);
            draftState = new UpdateContentStateCommand(changer, ContentState.Draft);
            publishedState = new UpdateContentStateCommand(changer, ContentState.Published);
            saveActiveContent = new ActiveContentSaveCommand();
			moveToPosition = new MoveToPositionCommand();
			unpublishedDate = new EnsureNotPublishedCommand();
			publishedDate = new EnsurePublishedCommand();
			updateReferences = new UpdateReferencesCommand();
        }
        public async Task UpdateObjectThatExist()
        {
            var runner   = MongoDbRunner.Start();
            var database = TestHelpers.GetDefaultDatabase(runner.ConnectionString);

            var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "1.json");

            runner.Import("okn", "objects", path, true);

            var config = new MapperConfiguration(cfg => cfg.AddProfile(typeof(MappingProfile)));
            var mapper = config.CreateMapper();

            var repo = new ObjectsRepository(mapper, new DbContext(database));

            var command = new UpdateObjectCommand("5af2796e32522f798f822a41")
            {
                Name = "TEST1"
            };

            await repo.UpdateObject(command, CancellationToken.None);

            ;
            // var entities = _database.GetCollection<ObjectEntity>("objects").Find(Builders<ObjectEntity>.Filter
            //     .Where(x => x.ObjectId == command.ObjectId)).ToList();

            // Assert.Single(entities);
            // Assert.Equal(command.Name, entities[0].Name);

            // var versions = _database.GetCollection<ObjectEntity>("objects_versions").Find(Builders<ObjectEntity>.Filter
            //     .Where(x => x.ObjectId == command.ObjectId)).ToList();
            //  Assert.Single(versions);
            //  Assert.Equal("TEST", versions[0].Name);
        }
Exemple #4
0
 public CommandFactory(IPersister persister, ISecurityManager security, IVersionManager versionMaker, IEditUrlManager editUrlManager, IContentAdapterProvider adapters, StateChanger changer)
 {
     this.persister      = persister;
     makeVersionOfMaster = On.Master(new MakeVersionCommand(versionMaker));
     replaceMaster       = new ReplaceMasterCommand(versionMaker);
     makeVersion         = new MakeVersionCommand(versionMaker);
     useNewVersion       = new UseNewVersionCommand(versionMaker);
     updateObject        = new UpdateObjectCommand();
     delete                = new DeleteCommand(persister.Repository);
     showPreview           = new RedirectToPreviewCommand(adapters);
     showEdit              = new RedirectToEditCommand(editUrlManager);
     useMaster             = new UseMasterCommand();
     clone                 = new CloneCommand();
     validate              = new ValidateCommand();
     this.security         = security;
     save                  = new SaveCommand(persister);
     incrementVersionIndex = new IncrementVersionIndexCommand(versionMaker);
     draftState            = new UpdateContentStateCommand(changer, ContentState.Draft);
     publishedState        = new UpdateContentStateCommand(changer, ContentState.Published);
     saveActiveContent     = new ActiveContentSaveCommand();
     moveToPosition        = new MoveToPositionCommand();
     unpublishedDate       = new EnsureNotPublishedCommand();
     publishedDate         = new EnsurePublishedCommand();
     updateReferences      = new UpdateReferencesCommand();
 }
        public CommandFactory(IPersister persister, ISecurityManager security, IVersionManager versionMaker, IEditUrlManager editUrlManager, IContentAdapterProvider adapters, StateChanger changer)
        {
            //this.persister = persister;
            //makeVersionOfMaster = On.Master(new MakeVersionCommand(versionMaker));
            //showEdit = new RedirectToEditCommand(editUrlManager);
            //clone = new CloneCommand();
            //unpublishedDate = new EnsureNotPublishedCommand(); // moved to StateChanger
            //ensurePublishedDate = new EnsurePublishedCommand();  // moved to StateChanger

            this.security = security;
            
            save = new SaveCommand(persister);
            delete = new DeleteCommand(persister.Repository);

            replaceMaster = new ReplaceMasterCommand(versionMaker);
            makeVersion = new MakeVersionCommand(versionMaker);
            useDraftCmd = new UseDraftCommand(versionMaker);
            saveOnPageVersion = new SaveOnPageVersionCommand(versionMaker);

            draftState = new UpdateContentStateCommand(changer, ContentState.Draft);
            publishedState = new UpdateContentStateCommand(changer, ContentState.Published);

            updateObject = new UpdateObjectCommand();
            useMaster = new UseMasterCommand();
            validate = new ValidateCommand();
            saveActiveContent = new ActiveContentSaveCommand();
			moveToPosition = new MoveToPositionCommand();
			updateReferences = new UpdateReferencesCommand();
        }
Exemple #6
0
        public async Task <IActionResult> Update([FromRoute] string objectId,
                                                 [FromBody] UpdateObjectViewModel request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var objectQuery = new ObjectQuery(objectId);

            var current = await _objectsRepository.GetObject(objectQuery, CancellationToken.None);

            if (current == null)
            {
                return(NotFound());
            }

            var currentUser = HttpContext.User;

            var updateCommand = new UpdateObjectCommand(objectId)
            {
                Name        = request.Name,
                Description = request.Description,
                Latitude    = request.Latitude,
                Longitude   = request.Longitude,
                Type        = request.Type
            };

            if (request.MainPhoto != null)
            {
                updateCommand.MainPhoto = new FileInfo
                {
                    FileId      = request.MainPhoto.FileId,
                    Description = request.MainPhoto.Description
                };
            }

            if (request.Photos != null)
            {
                updateCommand.Photos = request.Photos.Select(x => new FileInfo
                {
                    FileId      = x.FileId,
                    Description = x.Description
                }).ToList();
            }

            updateCommand.SetCreator(
                long.Parse(currentUser.FindFirstValue(ClaimTypes.NameIdentifier)).ToString(),
                currentUser.FindFirstValue(ClaimTypes.Name),
                currentUser.FindFirstValue(ClaimTypes.Email));

            await _objectsRepository.UpdateObject(updateCommand, CancellationToken.None);

            return(Ok());
        }
        public async Task UpdateObjectThatNotExist()
        {
            var runner   = MongoDbRunner.Start();
            var database = TestHelpers.GetDefaultDatabase(runner.ConnectionString);

            var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "1.json");

            runner.Import("okn", "objects", path, true);

            var repo = new ObjectsRepository(null, new DbContext(database));

            var command = new UpdateObjectCommand("5af27196e32522f798f822a41");

            await Assert.ThrowsAsync <ObjectNotExistException>(() => repo.UpdateObject(command, CancellationToken.None));
        }
        public CommandResult Update(Guid id, [FromBody] UpdateObjectCommand command)
        {
            command.setObjectId(id);
            command.setRequestHost(HttpContext.Request.Host.ToString());

            _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { Object = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method });

            CommandResult result = (CommandResult)_objectHandler.Handle(command);

            _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { Object = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode });

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }
        public ICommandResult Handle(UpdateObjectCommand command)
        {
            ICommandResult result = new CommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, "ObjectCommandHandler.Handle(Update)");

            try
            {
                Object obj = new Object(command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status);

                if (obj.Valid)
                {
                    if (_objectRepository.CheckExists(command.Id))
                    {
                        if (!_objectRepository.CheckExists(obj.Title))
                        {
                            if (_objectRepository.Update(command.Id, obj))
                            {
                                result = new CommandResult(200);
                            }
                        }

                        else if (_objectRepository.Valid)
                        {
                            result = new CommandResult(400, new Notification("Title", "Already in Use"));
                        }
                    }

                    else if (_objectRepository.Valid)
                    {
                        result = new CommandResult(400, new Notification("Object", "Could not be found"));
                    }
                }

                else
                {
                    result = new NewObjectCommandResult(400, obj.Notifications);
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, e);
            }

            return(result);
        }
Exemple #10
0
        public async Task UpdateObject(UpdateObjectCommand command, CancellationToken cancellationToken)
        {
            var filter = Builders <ObjectEntity> .Filter.Where(x => x.ObjectId == command.ObjectId);

            var originalEntity = await _context.Objects
                                 .Find(filter)
                                 .FirstOrDefaultAsync(cancellationToken);

            if (originalEntity == null)
            {
                throw new ObjectNotExistException("Object with this id doesn't exist");
            }

            SetObjectVersionIfNotExist(command, originalEntity);

            var newEntity = new ObjectEntity
            {
                ObjectId    = originalEntity.ObjectId,
                Federal     = originalEntity.Federal,
                Name        = command.Name ?? originalEntity.Name,
                Description = command.Description ?? originalEntity.Description,
                Longitude   = command.Longitude ?? originalEntity.Longitude,
                Latitude    = command.Latitude ?? originalEntity.Latitude,
                Type        = command.Type != default ? command.Type : originalEntity.Type,
                EventsCount = originalEntity.EventsCount,
                Events      = originalEntity.Events,
                MainPhoto   = command.MainPhoto != null
                    ? ProcessFileInfo(command.MainPhoto)
                    : null
            };

            if (command.Photos != null)
            {
                newEntity.Photos = command.Photos.Select(x => ProcessFileInfo(x)).ToList();
            }

            await IncObjectVersion(command, originalEntity, newEntity, cancellationToken);

            await _context.Objects.ReplaceOneAsync(filter, newEntity, cancellationToken : cancellationToken);
        }