Ejemplo n.º 1
0
        public async Task <OperationResult <bool> > InsertSocialNetwork(CreateCommunitySocial social)
        {
            if (!social.VerifyProperties())
            {
                return new OperationResult <bool>()
                       {
                           Success = false, Message = Messages.PARAMS_INVALID
                       }
            }
            ;

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var community = await GetByIdAsync(social.communityId);

                if (!community.Success)
                {
                    return new OperationResult <bool>()
                           {
                               Success = false, Message = community.Message
                           }
                }
                ;
                if (!community.Result.admins.Any(item => item.id == social.adminId))
                {
                    return new OperationResult <bool>()
                           {
                               Success = false, Message = Messages.COMMUNITY_HAS_NO_ADMIN
                           }
                }
                ;

                try
                {
                    var res = await communitySocialRepo.PostAsync(social);

                    scope.Complete();
                    return(new OperationResult <bool>()
                    {
                        Success = true, Message = Messages.COMMUNITY_SOCIAL_CREATED_SUCCESS, Result = true
                    });
                }
                catch (Exception ex)
                {
                    return(new OperationResult <bool>()
                    {
                        Success = false, Message = ex.Message
                    });
                }
            }
        }
        public Task <int> PostAsync(CreateCommunitySocial item)
        {
            return(Task.Factory.StartNew(() =>
            {
                var result = new CommunitySocialNetwork()
                {
                    Acess_Token = item.token, CommunityId = item.communityId, provider = item.social, Url = item.url
                };

                context.CommunitySocialNetwork.Add(result);

                try
                {
                    context.SaveChanges();
                    return result.CommunityId;
                }
                catch (Exception e)
                {
                    throw new ArgumentException(e.InnerException.Message);
                }
            }));
        }