예제 #1
0
        private static async Task SeedCatAndTag(ApplicationDbContext context)
        {
            var categorie = new PostOption
            {
                User  = tony,
                Key   = "[\"Web\",\"Mobile\"]",
                Value =
                    "[{\"value\":\"Web\",\"label\":\"Web\",\"className\":\"Select-create-option-placeholder\"},{\"value\":\"Mobile\",\"label\":\"Mobile\",\"className\":\"Select-create-option-placeholder\"}]",
                OptionType = PostOptionType.CategorieOptions.ToString()
            };

            var tag = new PostOption
            {
                User  = tony,
                Key   = "[\"ASP.Net\",\"React\"]",
                Value =
                    "[{\"value\":\"ASP.Net\",\"label\":\"ASP.Net\",\"className\":\"Select-create-option-placeholder\"},{\"value\":\"React\",\"label\":\"React\",\"className\":\"Select-create-option-placeholder\"}]",
                OptionType = PostOptionType.TagOptions.ToString()
            };

            await context.AddAsync(categorie);

            await context.AddAsync(tag);

            await context.SaveChangesAsync();
        }
        public async Task SavePost(PostViewModel postViewModel)
        {
            var user = await _userService.GetCurrentUserAsync();

            var postData = _mapper.Map <PostViewModel, Post>(postViewModel, options =>
            {
                options.AfterMap((src, dest) => dest.User = user);
            });

            var post = await _unitOfWork.Repository <Post>().AddAsync(postData);

            var tag = new PostOption
            {
                Key        = postViewModel.PostOptionsDefaultViewModel.TagViewModel.Key,
                Value      = postViewModel.PostOptionsDefaultViewModel.TagViewModel.Value,
                OptionType = PostOptionType.PostTags,
                User       = await _userService.GetCurrentUserAsync(),
                Post       = post
            };

            var categories = new PostOption
            {
                Key        = postViewModel.PostOptionsDefaultViewModel.CategoriesViewModel.Key,
                Value      = postViewModel.PostOptionsDefaultViewModel.CategoriesViewModel.Value,
                OptionType = PostOptionType.PostCategories,
                User       = await _userService.GetCurrentUserAsync(),
                Post       = post
            };

            await _unitOfWork.Repository <PostOption>().AddAsync(tag);

            await _unitOfWork.Repository <PostOption>().AddAsync(categories);
        }
예제 #3
0
        /// <summary>
        /// Posts a status update on Facebook and/or twitter
        /// </summary>
        /// <param name="option"></param>
        /// <param name="previousTweetId"></param>
        /// <param name="previousFacebookId"></param>
        /// <param name="previousTweeterName"></param>
        /// <param name="previousFacebookName"></param>
        public void PostOnline(PostOption postOption,
            long previousTweetId = 0,
            long previousFacebookId = 0,
            string previousTweeterName = null,
            string previousFacebookName = null)
        {
            if (postOption == PostOption.Twitter ||
                postOption == PostOption.Both)
            {
                TwitterService service =
                    new TwitterService(Helper.GetPublicKey(), Helper.GetSecretKey());

                service.AuthenticateWith(Helper.GetPublicToken(), Helper.GetSecretToken());

                SendTweetOptions options = new SendTweetOptions()
                {
                    Status = GetTweetText(previousTweeterName)
                };

                if (previousTweetId != 0 && previousTweeterName != null)
                {
                    options.InReplyToStatusId = previousTweetId;
                }

                service.SendTweet(options);

                if (service.Response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    //probably hit a rate limit, chill out!
                    Thread.Sleep(600000);
                }
            }

            if (postOption == PostOption.Facebook ||
                postOption == PostOption.Both)
            {
                //TODO: implement facebook here
            }
        }