public List <PhotoDb> GetPhotos(TwoButtonsContext context, int userId, int questionId, int answer, int count,
                                 DateTime bornAfter, DateTime bornBefore, int sex, string city)
 {
     return(context.PhotoDb.AsNoTracking()
            .FromSql(
                $"select * from dbo.getPhotos({userId}, {questionId}, {answer}, {count}, {bornAfter}, {bornBefore},  {sex}, {city})")
            .ToList());
 }
Beispiel #2
0
 public List <NewsAskedQuestionDto> GetNewsAskedQuestions(TwoButtonsContext context, int userId)
 {
     return(context.NewsAskedQuestionsDb.AsNoTracking().FromSql($"select * from dbo.getNewsAskedQuestions({userId})")
            .Select(x => new NewsAskedQuestionDto {
         NewsAskedQuestionDb = x, Priority = x.AnsweredFollowingsCount * 4
     }).OrderBy(x => x.NewsAskedQuestionDb.UserId)
            .ThenByDescending(x => x.Priority).ToListAsync().GetAwaiter().GetResult());
 }
Beispiel #3
0
        public List <NewsRecommendedQuestionDto> GetNewsRecommendedQuestions(TwoButtonsContext context, int userId)
        {
            var questions = context.NewsRecommendedQuestionsDb.AsNoTracking()
                            .FromSql($"select * from dbo.getNewsRecommendedQuestions({userId})").ToList();


            //.Select(x => new NewsRecommendedQuestionDto { NewsRecommendedQuestionDb = x, Priority = x.AnsweredFollowTo * 7 }).OrderBy(x => x.NewsRecommendedQuestionDb.UserId)
            //.ThenByDescending(x => x.Priority).ToListAsync().GetAwaiter().GetResult();



            var result = new List <NewsRecommendedQuestionDto>();

            foreach (var t in questions)
            {
                if (result.Count == 0 || result.All(x => x.QuestionId != t.QuestionId))
                {
                    result.Add(new NewsRecommendedQuestionDto
                    {
                        QuestionId            = t.QuestionId,
                        Condition             = t.Condition,
                        FirstOption           = t.FirstOption,
                        SecondOption          = t.SecondOption,
                        OriginalBackgroundUrl = t.OriginalBackgroundUrl,
                        QuestionType          = t.QuestionType,
                        AddedDate             = t.AddedDate,
                        UserId             = t.UserId,
                        FirstName          = t.FirstName,
                        LastName           = t.LastName,
                        OriginalAvatarUrl  = t.OriginalAvatarUrl,
                        LikesCount         = t.LikesCount,
                        DislikesCount      = t.DislikesCount,
                        YourFeedbackType   = t.YourFeedbackType,
                        YourAnswerType     = t.YourAnswerType,
                        IsFavorite         = t.IsFavorite,
                        IsSaved            = t.IsSaved,
                        CommentsCount      = t.CommentsCount,
                        FirstAnswersCount  = t.FirstAnswersCount,
                        SecondAnswersCount = t.SecondAnswersCount,

                        Priority = t.AnsweredFollowingsCount * 7,

                        RecommendedUsers = new List <RecommendedUserDto>()
                    });
                }
                var question = result.FirstOrDefault(x => x.QuestionId == t.QuestionId);
                if (question != null && question.RecommendedUsers.All(x => x.UserId != t.RecommendedUserId))
                {
                    question.RecommendedUsers
                    .Add(new RecommendedUserDto {
                        UserId = t.RecommendedUserId, FirstName = t.RecommendedUserFirstName, LastName = t.RecommendedUserLastName, SexType = t.RecommendedUserSexType
                    });
                }
            }

            return(result.OrderBy(x => x.UserId)
                   .ThenByDescending(x => x.Priority).ToList());
        }
Beispiel #4
0
        public async Task <bool> UpdateAnswer(TwoButtonsContext context, AnswerEntity answer)
        {
            context.AnswerEntities.Add(answer);

            //  var p = context.AnswerEntities.ToList();
            // var y = p;

            return(await context.SaveChangesAsync() > 0);

            //return await _context.Database.ExecuteSqlCommandAsync(
            //         $"updateAnswer {userId}, {questionId}, {answerType}, {answered}") > 0;
        }
Beispiel #5
0
        private void GetTagsAndPhotos(TwoButtonsContext context, int userId, int questionId, out IEnumerable <TagDb> tags,
                                      out IEnumerable <PhotoDb> firstPhotos, out IEnumerable <PhotoDb> secondPhotos)
        {
            var photosCount = 100;
            var minAge      = 0;
            var maxAge      = 100;
            var sex         = 0;
            var city        = string.Empty;

            tags        = MainDb.Tags.GetTags(context, questionId);
            firstPhotos = MainDb.Questions.GetPhotos(context, userId, questionId, 1, photosCount, maxAge.WhenBorned(),
                                                     minAge.WhenBorned(), sex, city);
            secondPhotos = MainDb.Questions.GetPhotos(context, userId, questionId, 2, photosCount, maxAge.WhenBorned(),
                                                      minAge.WhenBorned(), sex, city);
        }
Beispiel #6
0
        private List <NewsAnsweredQuestionViewModel> GetNewsAnsweredQuestionsAsync(TwoButtonsContext context, int userId,
                                                                                   BackgroundSizeType backgroundSizeType)
        {
            var userAnsweredQuestions = MainDb.News.GetNewsAnsweredQuestions(context, userId);
            //return new List<NewsAnsweredQuestionViewModel>();
            var result = new List <NewsAnsweredQuestionViewModel>();

            foreach (var question in userAnsweredQuestions)
            {
                GetTagsAndPhotos(context, userId, question.NewsAnsweredQuestionDb.QuestionId, out var tags, out var firstPhotos,
                                 out var secondPhotos);
                var resultQuestion =
                    question.MapToNewsAnsweredQuestionsViewModel(MediaConverter, tags, firstPhotos, secondPhotos,
                                                                 backgroundSizeType);
                result.Add(resultQuestion);
            }
            return(result);
        }
Beispiel #7
0
        public bool UpdateAnswer(TwoButtonsContext context, int userId, int questionId, AnswerType answerType)
        {
            var answered = DateTime.Now;

            // var m = context.AnswerEntities.ToList();
            // var t = m;
            context.AnswerEntities.Add(new AnswerEntity
            {
                AnswerType = answerType,
                QuestionId = questionId,
                UserId     = userId
            });

            //  var p = context.AnswerEntities.ToList();
            // var y = p;

            return(context.SaveChanges() > 0);
            //return await _context.Database.ExecuteSqlCommandAsync(
            //         $"updateAnswer {userId}, {questionId}, {answerType}, {answered}") > 0;
        }
Beispiel #8
0
        //private void Task(object jobState)
        //{
        //  var job = (JobState)jobState;
        //  if (job.RemainingIteration <= 0) job.Timer.Dispose();
        //  while (job.BotVotings.Count > 1)
        //  {
        //    Thread.Sleep(2000);
        //    var bot = job.BotVotings.Pop();
        //    job.Db.QuestionRepository.UpdateAnswer(bot.BotId, bot.QuestionId, bot.AnswerType);
        //  }

        //  job.RemainingIteration--;
        //}

        private async void Task(object jobState)
        {
            var job = (JobState)jobState;

            var db = new TwoButtonsContext(job.DbOptions); // TODO интересно проверить теорию, что можно и не создавать

            var answered = DateTime.Now;
            // var m = context.AnswerEntities.ToList();
            // var t = m;
            var answer = new AnswerEntity
            {
                AnswerType   = job.AnswerType,
                QuestionId   = job.QuestionId,
                UserId       = job.BotId,
                AnsweredDate = answered,
                IsDeleted    = false,
                FeedbackType = QuestionFeedbackType.Like
            };

            await job.Db.QuestionRepository.UpdateAnswer(db, answer);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            //AddWrapper addWrapper = new AddWrapper();
            //if (addWrapper.TryAddUser("", "testAdd5", 1525, 235, 15, "testPhone5", "", "", out int userId))
            //    Console.WriteLine(userId);

            List <int> p = new List <int>();

            //CommentsWrapper commentsWrapper = new CommentsWrapper();
            //if (commentsWrapper.TryGetComments("",1,1,100,out IEnumerable<CommentDb> comments))
            //    Console.WriteLine(comments.FirstOrDefault().Comment);

            using (var db = new TwoButtonsContext(CreateOptions()))
            {
                //var user = db.UserDb.FirstOrDefault();
                //Console.WriteLine(user?.Login);
                //if (AccountWrapper.TryGetIdentification(db, "govjad", "1", out int userId))
                //    Console.WriteLine(userId);
            }

            Console.WriteLine("Hello World!");
        }
 public FeedbackRepository(TwoButtonsContext db)
 {
     _db = db;
 }
 public UserQuestionsRepository(TwoButtonsContext db)
 {
     _db = db;
 }
 public UserInfoRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #13
0
 public BotsRepository(TwoButtonsContext context, TwoButtonsAccountContext contextAccount)
 {
     _context        = context;
     _contextAccount = contextAccount;
 }
Beispiel #14
0
 public NotificationsDataUnitOfWork(TwoButtonsContext dbMain)
 {
     _dbMain = dbMain;
 }
 public ComplaintsRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #16
0
 public CityRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #17
0
 public MonitoringRepository(TwoButtonsContext db)
 {
     _db = db;
 }
 public TagsRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #19
0
 public RecommendedPeopleRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #20
0
        public async Task <IActionResult> GetNews([FromBody] GetNewsViewModel newsVm)
        {
            if (!ModelState.IsValid)
            {
                return(new BadResponseResult(ModelState));
            }

            Logger.LogInformation($"{nameof(NewsQuestionsController)}.{nameof(GetNews)}.Start");
            var userId          = newsVm.UserId;
            var questionsOffset = newsVm.PageParams.Offset;
            var questionsCount  = newsVm.PageParams.Count;

            var askedList       = new List <NewsAskedQuestionViewModel>();
            var answeredList    = new List <NewsAnsweredQuestionViewModel>();
            var favoriteList    = new List <NewsFavoriteQuestionViewModel>();
            var commentedList   = new List <NewsCommentedQuestionViewModel>();
            var recommentedList = new List <NewsRecommendedQuestionViewModel>();

            Parallel.Invoke(() =>
            {
                using (var context = new TwoButtonsContext(DbOptions))
                {
                    askedList = GetNewsAskedQuestionsAsync(context, userId, newsVm.BackgroundSizeType);
                }
            }, () =>
            {
                using (var context = new TwoButtonsContext(DbOptions))
                {
                    answeredList = GetNewsAnsweredQuestionsAsync(context, userId, newsVm.BackgroundSizeType);
                }
            }, () =>
            {
                using (var context = new TwoButtonsContext(DbOptions))
                {
                    favoriteList = GetNewsFavoriteQuestionsAsync(context, userId, newsVm.BackgroundSizeType);
                }
            }, () =>
            {
                using (var context = new TwoButtonsContext(DbOptions))
                {
                    commentedList = GetNewsCommentedQuestions(context, userId, newsVm.BackgroundSizeType);
                }
            }, () =>
            {
                using (var context = new TwoButtonsContext(DbOptions))
                {
                    recommentedList = TryGetNewsRecommendedQuestions(context, userId, newsVm.BackgroundSizeType);
                }
            });

            var newsList = new List <NewsQuestionBaseViewModel>(askedList.Count + answeredList.Count + commentedList.Count +
                                                                favoriteList.Count + recommentedList.Count);

            newsList.AddRange(askedList);
            newsList.AddRange(answeredList);
            newsList.AddRange(commentedList);
            newsList.AddRange(favoriteList);
            newsList.AddRange(recommentedList);

            var mainList = newsList.OrderBy(x => x.Author.UserId).ToList();

            var removeList = new List <NewsQuestionBaseViewModel>();
            var compare    = new NewsQuestionBaseCompare();

            for (var i = 0; i < mainList.Count - 1; i++)
            {
                if (compare.GetHashCode(mainList[i]) == compare.GetHashCode(mainList[i + 1]) ||
                    compare.Equals(mainList[i], mainList[i + 1]))
                {
                    removeList.Add(mainList[i].Priority > mainList[i + 1].Priority ? mainList[i + 1] : mainList[i]);
                }
            }

            var resultList = mainList.Except(removeList).OrderByDescending(x => x.Priority).Skip(questionsOffset)
                             .Take(questionsCount).ToList();

            var answeredListResultList    = new List <NewsAnsweredQuestionViewModel>();
            var favoriteListResultList    = new List <NewsFavoriteQuestionViewModel>();
            var commentedListResultList   = new List <NewsCommentedQuestionViewModel>();
            var recommentedListResultList = new List <NewsRecommendedQuestionViewModel>();

            var askedListResultList = new List <NewsAskedQuestionViewModel>();

            var length = questionsCount > resultList.Count ? resultList.Count : questionsCount;

            for (var i = 0; i < length; i++)
            {
                resultList[i].Position = i + questionsOffset;
                switch (resultList[i].NewsType)
                {
                case NewsType.Answered:
                    answeredListResultList.Add((NewsAnsweredQuestionViewModel)resultList[i]);
                    break;

                case NewsType.Asked:
                    askedListResultList.Add((NewsAskedQuestionViewModel)resultList[i]);
                    break;

                case NewsType.Commented:
                    commentedListResultList.Add((NewsCommentedQuestionViewModel)resultList[i]);
                    break;

                case NewsType.Favorite:
                    favoriteListResultList.Add((NewsFavoriteQuestionViewModel)resultList[i]);
                    break;

                case NewsType.Recommended:
                    recommentedListResultList.Add((NewsRecommendedQuestionViewModel)resultList[i]);
                    break;
                }
            }

            var result = new NewsViewModel
            {
                NewsAskedQuestions       = askedListResultList,
                NewsAnsweredQuestions    = answeredListResultList,
                NewsFavoriteQuestions    = favoriteListResultList,
                NewsCommentedQuestions   = commentedListResultList,
                NewsRecommendedQuestions = recommentedListResultList
            };

            await Hub.Monitoring.UpdateUrlMonitoring(newsVm.UserId, UrlMonitoringType.GetsQuestionsNews);

            Logger.LogInformation($"{nameof(NewsQuestionsController)}.{nameof(GetNews)}.End");
            return(new OkResponseResult(result));
        }
Beispiel #21
0
 public UserInfoRepository(TwoButtonsContext contextMain)
 {
     _contextMain = contextMain;
 }
 public NotificationsRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #23
0
 public AccountRepository(TwoButtonsContext db)
 {
     _db = db;
 }
 public NotificationsRepository(TwoButtonsContext context)
 {
     _context = context;
 }
 public List <TagDb> GetTags(TwoButtonsContext context, int questionId)
 {
     return(context.TagDb.AsNoTracking().FromSql($"select * from dbo.getTags({questionId})").ToList());
 }
Beispiel #26
0
 public RecommendedFollowingsRepository(TwoButtonsContext db)
 {
     _db = db;
 }
Beispiel #27
0
 public AccountDataUnitOfWork(TwoButtonsContext dbMain, TwoButtonsAccountContext dbAccount)
 {
     _dbMain    = dbMain;
     _dbAccount = dbAccount;
 }
Beispiel #28
0
 public AuthorizationUnitOfWork(TwoButtonsContext dbMain, TwoButtonsAccountContext dbAccount)
 {
     _dbMain    = dbMain;
     _dbAccount = dbAccount;
 }
Beispiel #29
0
 public FollowersRepository(TwoButtonsContext db)
 {
     _db = db;
 }