コード例 #1
0
        public async Task <IActionResult> GetActivityRules(string countryId)
        {
            try
            {
                var currentRules = await _countryService.GetCountryActivityRules(countryId);

                if (currentRules is null)
                {
                    currentRules = new CountryActivityRule
                    {
                        CountryId   = countryId,
                        Article     = 0,
                        ArticleLike = 0,
                        ArticleView = 0,
                        Story       = 0,
                        StoryLike   = 0,
                        StoryView   = 0,
                        Comment     = 0,
                        CommentLike = 0,
                        Share       = 0,
                        Referral    = 0,
                    };
                }

                return(Json(new { IsSuccess = true, rules = currentRules }));
            }
            catch (Exception e)
            {
                return(Json(new { IsSuccess = false, Message = e.Message }));
            }
        }
コード例 #2
0
        public bool UpdateCountryActivityRules(CreateCountryActivityRule activityRules)
        {
            try
            {
                var currentRules = _countryRuleRepository
                                   .Get(x => x.CountryId == activityRules.CountryId &&
                                        !x.IsDeleted)
                                   .SingleOrDefault();

                if (currentRules is object)
                {
                    currentRules.IsDeleted = true;

                    _countryRuleRepository.Update(currentRules);
                }

                var newRules = new CountryActivityRule
                {
                    Id          = ObjectId.GenerateNewId().ToString(),
                    CountryId   = activityRules.CountryId,
                    Article     = activityRules.Article,
                    ArticleLike = activityRules.ArticleLike,
                    ArticleView = activityRules.ArticleView,
                    Story       = activityRules.Story,
                    StoryLike   = activityRules.StoryLike,
                    StoryView   = activityRules.StoryView,
                    Comment     = activityRules.Comment,
                    CommentLike = activityRules.CommentLike,
                    Share       = activityRules.Share,
                    Referral    = activityRules.Referral,
                };

                _countryRuleRepository.Add(newRules);

                return(true);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Unable to update country activity rules: " + e.Message);
            }
        }