Beispiel #1
0
        public IEnumerable <IEvent> Handle(ReorderThemes cmd)
        {
            var events        = new List <IDomainEvent>();
            var updatedThemes = new List <Theme>();

            for (int i = 0; i < cmd.Themes.Count; i++)
            {
                var themeId   = cmd.Themes[i];
                var sortOrder = i + 1;

                var theme = _themeRepository.GetById(themeId);

                if (theme == null)
                {
                    throw new Exception("Theme not found.");
                }

                if (theme.SortOrder != sortOrder)
                {
                    theme.Reorder(sortOrder);
                    updatedThemes.Add(theme);
                    events.AddRange(theme.Events);
                }
            }

            _themeRepository.Update(updatedThemes);

            return(events);
        }
Beispiel #2
0
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var theme = _repository.GetById(id);

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

            return(View(theme));
        }
Beispiel #3
0
        public async Task <ThemeAdminModel> GetForAdminAsync(Guid id)
        {
            var theme = _themeRepository.GetById(id);

            if (theme == null || theme.Status == ThemeStatus.Deleted)
            {
                return(null);
            }
            return(_mapper.Map <ThemeAdminModel>(theme));
        }
        /// <summary>
        /// Finds a theme by id
        /// </summary>
        /// <param name="id"> Id</param>
        /// <returns>The theme</returns>
        public BllTheme GetById(int id)
        {
            var theme = themeRepository.GetById(id);

            if (theme == null)
            {
                return(null);
            }
            return(theme.ToBllTheme());
        }
        public IAggregateRoot Handle(ReorderTheme cmd)
        {
            var language = _themeRepository.GetById(cmd.AggregateRootId);

            if (language == null)
            {
                throw new Exception("Theme not found.");
            }

            language.Reorder(cmd.Order);
            _themeRepository.Update(language);

            return(language);
        }
        public ICollection <IEvent> Handle(DeleteTheme command)
        {
            var theme = _themeRepository.GetById(command.Id);

            if (theme == null)
            {
                throw new Exception("Theme not found.");
            }

            theme.Delete();

            _themeRepository.Update(theme);

            return(theme.Events);
        }
Beispiel #7
0
        public ICollection <IEvent> Handle(UpdateThemeDetails cmd)
        {
            var theme = _themeRepository.GetById(cmd.Id);

            if (theme == null)
            {
                throw new Exception("Theme not found.");
            }

            theme.UpdateDetails(cmd, _validator);

            _themeRepository.Update(theme);

            return(theme.Events);
        }
Beispiel #8
0
        public IAggregateRoot Handle(ActivateTheme command)
        {
            var theme = _themeRepository.GetById(command.Id);

            if (theme == null)
            {
                throw new Exception("Theme not found.");
            }

            theme.Activate();

            _themeRepository.Update(theme);

            return(theme);
        }
Beispiel #9
0
        public void Should_save_new_theme()
        {
            var newTheme         = ThemeFactory.Theme(Guid.NewGuid(), "Name 3", "Description 3", "Folder 3");
            var newThemeDbEntity = new ThemeDbEntity
            {
                Id          = newTheme.Id,
                Name        = newTheme.Name,
                Description = newTheme.Description,
                Folder      = newTheme.Folder
            };

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <ThemeDbEntity>(newTheme)).Returns(newThemeDbEntity);
            mapperMock.Setup(x => x.Map <Theme>(newThemeDbEntity)).Returns(newTheme);

            _sut = new ThemeRepository(_dbContext, mapperMock.Object);

            _sut.Create(newTheme);

            var actual = _sut.GetById(newTheme.Id);

            Assert.NotNull(actual);
        }
Beispiel #10
0
        public bool DoesThemeExist(Guid id)
        {
            var theme = _themeRepository.GetById(id);

            return(theme != null && theme.Status != ThemeStatus.Deleted);
        }
Beispiel #11
0
        public void Should_return_theme_by_id()
        {
            var actual = _sut.GetById(_themeId1);

            Assert.NotNull(actual);
        }
Beispiel #12
0
 public ThemeEntity GetThemeEntityById(int id)
 {
     return(themeRepository.GetById(id).ToBllTheme());
 }
Beispiel #13
0
        public ThemeAdminModel GetForAdmin(Guid id)
        {
            var theme = _themeRepository.GetById(id);

            return(theme == null ? null : _mapper.Map <ThemeAdminModel>(theme));
        }