Example #1
0
        public void UpdateAdvertisingLocalizationFromModel(AdvertisingModel model)
        {
            var originalAdvertisingLocalization = advertisingLocalizationRepository.Set()
                                                  .FirstOrDefault(al => al.AdvertisingId == model.AdvertisingId && al.LanguageId == model.LanguageId);

            if (originalAdvertisingLocalization == null)
            {
                throw new ArgumentException($"no localization in language {model.LanguageId} of advertising {model.AdvertisingId}", nameof(model));
            }

            var newAdvertisingLocalization = GetAdvertisingLocalizationFromModel(model);

            originalAdvertisingLocalization.Headline = newAdvertisingLocalization.Headline;

            advertisingLocalizationRepository.Update(originalAdvertisingLocalization);
        }
Example #2
0
        public SportArticle UpdateSportArticleFromModel(int sportArticleId, SportArticleModel model)
        {
            var sportArticle = _sportArticleRepository.Set()
                               .FirstOrDefault(sa => sa.ArticleId == sportArticleId);

            if (sportArticle == null)
            {
                throw new Exception($"SportArticle {sportArticleId} not found");
            }

            var newSportArticle = GetSportArticleFromModel(model);

            sportArticle.TeamId = newSportArticle.TeamId;

            _sportArticleRepository.Update(sportArticle);

            return(sportArticle);
        }
Example #3
0
        public void UpdateConferenceLocalizationFromModel(ConferenceModel model)
        {
            var conference = GetConferenceById(model.ConferenceId);

            var originalConferenceLocalization = _conferenceLocalizationRepository.Set()
                                                 .FirstOrDefault(al => al.ConferenceId == conference.Id && al.LanguageId == model.LanguageId);

            if (originalConferenceLocalization == null)
            {
                throw new Exception($"no previous localization in language {model.LanguageId} of conference {model.ConferenceId}");
            }

            var newConferenceLocalization = GetConferenceLocalizationFromModel(conference, model);

            originalConferenceLocalization.Name = newConferenceLocalization.Name;

            _conferenceLocalizationRepository.Update(originalConferenceLocalization);
        }
Example #4
0
        public Article UpdateArticleById(int id, ArticleModel model)
        {
            var originalArticle = _articleRepository.Set().FirstOrDefault(a => a.Id == id);

            if (originalArticle == null)
            {
                throw new Exception($"can\'t find article {id}");
            }

            var article = _articleModelService.GetArticleFromModel(model);


            originalArticle.Image    = article.Image;
            originalArticle.Category = article.Category;
            originalArticle.Content  = article.Content;

            _articleRepository.Update(originalArticle);

            return(originalArticle);
        }
Example #5
0
        public ArticleLocalization UpdateArticleLocalizationFromModel(ArticleModel model)
        {
            var article = GetArticleById(model.ArticleId);

            var originalArticleLocalization = _articleLocalizationRepository.Set()
                                              .FirstOrDefault(al => al.ArticleId == article.Id && al.LanguageId == model.LanguageId);

            if (originalArticleLocalization == null)
            {
                throw new Exception($"no previous localization in language {model.LanguageId} of article {model.ArticleId}");
            }

            var newArticleLocalization = _articleModelService.GetArticleLocalizationFromModel(article, model);

            originalArticleLocalization.Headline = newArticleLocalization.Headline;
            originalArticleLocalization.Text     = newArticleLocalization.Text;
            originalArticleLocalization.Caption  = newArticleLocalization.Caption;
            originalArticleLocalization.Alt      = newArticleLocalization.Alt;

            _articleLocalizationRepository.Update(originalArticleLocalization);

            return(originalArticleLocalization);
        }
Example #6
0
        public MainArticle UpdateMainArticleFromModel(int mainArticleId, MainArticleModel model)
        {
            var mainArticle = _mainArticleRepository.Set().FirstOrDefault(ma => ma.ArticleId == mainArticleId);

            if (mainArticle == null)
            {
                throw new Exception($"main article {mainArticleId} not found");
            }

            var newMainArticle = GetMainArticleFromModel(model);

            if (!mainArticle.Show && newMainArticle.Show && !CheckMainArticleState())
            {
                throw new Exception($"can not update status for main article {mainArticle.ArticleId} - reached maximum count. Remove or hide any existing main articles");
            }

            mainArticle.Article = newMainArticle.Article;
            mainArticle.Show    = newMainArticle.Show;

            _mainArticleRepository.Update(mainArticle);

            return(mainArticle);
        }