コード例 #1
0
        private SocialBase MapToSocial(SocialCreateModel model)
        {
            var bulletin = model.Map <SocialBase>();

            bulletin.PublishDate = DateTime.UtcNow;
            bulletin.CreatorId   = bulletin.OwnerId = _memberService.GetCurrentMemberId();

            if (model.NewMedia.HasValue())
            {
                bulletin.MediaIds = _mediaHelper.CreateMedia(model, MediaFolderTypeEnum.SocialsContent);
            }

            return(bulletin);
        }
コード例 #2
0
        private async Task OnBulletinCreatedAsync(SocialBase social, SocialCreateModel model)
        {
            if (model.GroupId.HasValue)
            {
                await _groupActivityService.AddRelationAsync(model.GroupId.Value, social.Id);
            }

            var extendedBulletin = _socialService.Get(social.Id);

            extendedBulletin.GroupId = model.GroupId;

            await _activityTagsHelper.ReplaceTagsAsync(social.Id, model.TagIdsData);

            if (model.Description.HasValue())
            {
                await ResolveMentionsAsync(model.Description, social);
            }
        }
コード例 #3
0
        private void OnBulletinCreated(SocialBase social, SocialCreateModel model)
        {
            var groupId = HttpContext.Current.Request.QueryString.GetGroupIdOrNone();

            if (groupId.HasValue)
            {
                _groupActivityService.AddRelation(groupId.Value, social.Id);
            }

            var extendedBulletin = _socialService.Get(social.Id);

            extendedBulletin.GroupId = groupId;


            _activityTagsHelper.ReplaceTags(social.Id, model.TagIdsData);

            if (model.Description.HasValue())
            {
                ResolveMentions(model.Description, social);
            }
        }
コード例 #4
0
        public async Task <IHttpActionResult> Create(SocialCreateModel social)
        {
            //if (!_permissionsService.Check(new PermissionSettingIdentity(PermissionActionEnum.Create, PermissionResourceTypeEnum.Social)))
            if (!await _socialService.CanCreateAsync(social.GroupId))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var mappedSocial = MapToSocial(social);

            var socialId = await _socialService.CreateAsync(mappedSocial);

            mappedSocial.Id = socialId;

            await OnBulletinCreatedAsync(mappedSocial, social);

            ReloadFeed();

            var result = await GetSocialViewModelAsync(socialId);

            return(Ok(result.Links.Details));
        }
コード例 #5
0
        public async Task <ActionResult <SettingModel> > PutSocialSetting([FromRoute, Required] int socialId,
                                                                          [FromRoute, Required] int appId, [FromBody] SocialCreateModel social)
        {
            string error = _authService.CheckId(User.Identity.Name, appId, socialId);

            if (error != null)
            {
                return(BadRequest(ErrorModel.IdErrorModel(error)));
            }

            var set = _backOfficeContext.Settings.First(s => (s.AppId == appId) && (s.SocialId == socialId));

            set.ClientId  = social.ClientId;
            set.SecretKey = social.SecretKey;
            set.Scope     = social.Scope;
            await _backOfficeContext.SaveChangesAsync();

            return(Ok(
                       new SettingModel(
                           set.Id,
                           set.AppId,
                           _backOfficeContext.Apps.FirstOrDefault(s => s.Id == appId)?.Name,
                           set.SocialId,
                           _backOfficeContext.Socials.FirstOrDefault(s => s.Id == socialId)?.Name,
                           set.ClientId, set.SecretKey, set.Scope, set.IsActive)));
        }
コード例 #6
0
        public async Task <ActionResult <SettingModel> > PostSocialSetting([FromRoute, Required] int socialId,
                                                                           [FromRoute, Required] int appId, [FromBody] SocialCreateModel social)
        {
            string error = _authService.CheckId(User.Identity.Name, appId, socialId);

            switch (error)
            {
            case "This setting is not existed":
            {
                var setting = new Setting()
                {
                    ClientId  = social.ClientId,
                    SecretKey = social.SecretKey,
                    Scope     = social.Scope,
                    AppId     = appId,
                    SocialId  = socialId,
                    IsActive  = true
                };
                var set = (await _backOfficeContext.Settings.AddAsync(setting)).Entity;
                await _backOfficeContext.SaveChangesAsync();

                return(Ok(new SettingModel(set.Id, set.AppId,
                                           _backOfficeContext.Apps.FirstOrDefault(s => s.Id == appId)?.Name, set.SocialId,
                                           _backOfficeContext.Socials.FirstOrDefault(s => s.Id == socialId)?.Name, set.ClientId,
                                           set.SecretKey,
                                           set.Scope, set.IsActive)));
            }

            case null:
                return(BadRequest(ErrorModel.IdErrorModel("This setting already exist")));

            default:
                return(BadRequest(ErrorModel.IdErrorModel(error)));
            }
        }