Example #1
0
        public IEnumerable <CategoryModel> GetCategories(int languageId)
        {
            var language = _languageService.GetLanguage(languageId);
            var query    = (from a in _categoryRepository.Set()
                            select a).ToList();
            var models = query.Select(ca => GetCategoryModel(ca, language));

            return(models);
        }
Example #2
0
        public void DeleteArticleById(int id)
        {
            var article = _articleRepository.Set().FirstOrDefault(a => a.Id == id);

            if (article == null)
            {
                throw new Exception($"Article {id} not found");
            }

            _articleRepository.Delete(article);
        }
Example #3
0
        public void DeleteAdvertisingLocalizationById(int advertisingId, int languageId)
        {
            var advertisingLocalization = advertisingLocalizationRepository.Set()
                                          .FirstOrDefault(al => al.AdvertisingId == advertisingId && al.LanguageId == languageId);

            if (advertisingLocalization == null)
            {
                throw new ArgumentException($"localization for advertising {advertisingId} in language {languageId} not found");
            }

            advertisingLocalizationRepository.Delete(advertisingLocalization);
        }
Example #4
0
        public void AddNewCategoryAdFromModel(AdvertisingModel model)
        {
            var categoryAd = GetCategoryAdFromModel(model);

            if (categoryAdRepository.Set()
                .Any(al => al.AdvertisingId == model.AdvertisingId && al.CategoryId == model.CategoryId))
            {
                throw new ArgumentException($"CategoryAd in category {model.CategoryId} for advertising {model.AdvertisingId} already exists", nameof(model));
            }

            categoryAdRepository.Insert(categoryAd);
        }
Example #5
0
        public void AddNewConferenceLocalizationFromModel(ConferenceModel model)
        {
            var conference = GetConferenceById(model.ConferenceId);

            var conferenceLocalization = GetConferenceLocalizationFromModel(conference, model);

            if (_conferenceLocalizationRepository.Set()
                .Any(al => al.ConferenceId == model.ConferenceId && al.LanguageId == model.LanguageId))
            {
                throw new Exception($"localization in language {model.LanguageId} for conference {model.ConferenceId} already exists");
            }

            _conferenceLocalizationRepository.Insert(conferenceLocalization);
        }
Example #6
0
        public ArticleLocalization GetArticleLocalization(int articleId, int languageId)
        {
            var article = _articleRepository.Set().FirstOrDefault(a => a.Id == articleId);

            if (article == null)
            {
                throw new Exception("article was null");
            }

            var language = _languageRepository.Set().FirstOrDefault(l => l.Id == languageId);

            if (language == null)
            {
                throw new Exception("language was null");
            }

            return(_articleLocalizationRepository.Set().FirstOrDefault(al => al.Article == article && al.Language == language));
        }
Example #7
0
        public SportArticle GetConnectedSportArticle(Article article)
        {
            if (article == null)
            {
                throw new ArgumentNullException(nameof(article));
            }

            return(_sportArticleRepository.Set().Include(sa => sa.Article).FirstOrDefault(sa => sa.Article == article));
        }
Example #8
0
        public TeamLocalization AddNewTeamLocalizationFromModel(TeamModel model)
        {
            var team = GetTeamFromModel(model);

            var teamLocalization = GetTeamLocalizationFromModel(team, model);

            if (_teamLocalizationRepository.Set()
                .Any(al => al.TeamId == model.TeamId && al.LanguageId == model.LanguageId))
            {
                throw new ArgumentException($"localization in language {model.LanguageId} for team {model.TeamId} already exists", nameof(model));
            }
            _teamLocalizationRepository.Insert(teamLocalization);
            return(teamLocalization);
        }
Example #9
0
        public void DeleteMainArticle(int mainArticleId)
        {
            var mainArticle = _mainArticleRepository.Set().FirstOrDefault(ma => ma.ArticleId == mainArticleId);

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

            _mainArticleRepository.Delete(mainArticle);
        }
        public Article GetArticleFromModel(ArticleModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var category = _categoryRepository.Set().FirstOrDefault(c => c.Id == model.CategoryId);

            var image = _imageRepository.Set().FirstOrDefault(i => i.Id == model.ImageId);

            if (image == null && model.ImageUri != default)
            {
                image = new Image
                {
                    Uri = model.ImageUri
                };
            }

            var content = _contentRepository.Set().FirstOrDefault(c => c.Id == model.ContentId);

            if (content == null && (model.DatePublished != null || model.IsPublished != null || model.ShowComments != null))
            {
                content = new Content
                {
                    IsPublished  = (bool)model.IsPublished,
                    Datetime     = (DateTime)model.DatePublished,
                    ShowComments = (bool)model.ShowComments
                };
            }

            return(new Article
            {
                Id = model.ArticleId,
                Image = image,
                Category = category,
                Content = content
            });
        }
Example #11
0
        private CategoryAd GetCategoryAdFromModel(AdvertisingModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var category    = categoryRepository.Set().FirstOrDefault(l => l.Id == model.CategoryId);
            var advertising = advertisingRepository.Set().FirstOrDefault(l => l.Id == model.AdvertisingId);

            if (category == null || advertising == null)
            {
                throw new ArgumentException($"can\'t find category {model.CategoryId} or advertising {model.AdvertisingId}", nameof(model));
            }

            return(new CategoryAd
            {
                Advertising = advertising,
                Category = category,
                Displayed = model.Displayed,
                Opened = model.Opened
            });
        }