Пример #1
0
        public async Task UserData_Information_SubscriptionTests()
        {
            //ensure users with no subscriptions don't error out
            var noSubUserName = "******";

            TestDataInitializer.CreateUser(noSubUserName);

            var userData = new Domain.UserData(noSubUserName);

            //var userData = new Domain.UserData(noSubUserName);
            Assert.AreEqual(0, userData.SubverseSubscriptions.Count());
            Assert.AreEqual(false, userData.HasSubscriptions());
            Assert.AreEqual(false, userData.HasSubscriptions(DomainType.Subverse));

            //test subscription
            var subUserName = "******";

            TestDataInitializer.CreateUser(subUserName);

            var user = TestHelper.SetPrincipal(subUserName);
            var cmd  = new SubscribeCommand(new DomainReference(DomainType.Subverse, SUBVERSES.Unit), Domain.Models.SubscriptionAction.Subscribe).SetUserContext(user);
            var x    = await cmd.Execute();

            VoatAssert.IsValid(x);

            userData = new Domain.UserData(subUserName);

            Assert.AreEqual(1, userData.SubverseSubscriptions.Count());
            Assert.AreEqual(SUBVERSES.Unit, userData.SubverseSubscriptions.First());
            Assert.AreEqual(true, userData.HasSubscriptions());
            Assert.AreEqual(true, userData.HasSubscriptions(DomainType.Subverse));
            Assert.AreEqual(true, userData.IsUserSubverseSubscriber(SUBVERSES.Unit));
        }
Пример #2
0
        public async Task UserData_Information_SubscriptionTests()
        {
            //ensure users with no subscriptions don't error out
            var noSubUserName = "******";

            VoatDataInitializer.CreateUser(noSubUserName);

            var userData = new Domain.UserData(noSubUserName);

            //var userData = new Domain.UserData(noSubUserName);
            Assert.AreEqual(0, userData.SubverseSubscriptions.Count());
            Assert.AreEqual(false, userData.HasSubscriptions());
            Assert.AreEqual(false, userData.HasSubscriptions(DomainType.Subverse));

            //test subscription
            var subUserName = "******";

            VoatDataInitializer.CreateUser(subUserName);

            TestHelper.SetPrincipal(subUserName);
            var cmd = new SubscriptionCommand(Domain.Models.DomainType.Subverse, Domain.Models.SubscriptionAction.Subscribe, "unit");
            var x   = await cmd.Execute();

            userData = new Domain.UserData(subUserName);

            Assert.AreEqual(1, userData.SubverseSubscriptions.Count());
            Assert.AreEqual("unit", userData.SubverseSubscriptions.First());
            Assert.AreEqual(true, userData.HasSubscriptions());
            Assert.AreEqual(true, userData.HasSubscriptions(DomainType.Subverse));
            Assert.AreEqual(true, userData.IsUserSubverseSubscriber("unit"));
        }
Пример #3
0
 public void UserData_ValidateUser_Constructor_5()
 {
     VoatAssert.Throws <VoatNotFoundException>(() => {
         string user  = "******";
         var voatData = new Domain.UserData(user, true);
     });
 }
Пример #4
0
 public void UserData_ValidateUser_Constructor_4()
 {
     VoatAssert.Throws <VoatNotFoundException>(() => {
         string user  = "******";
         var voatData = new Domain.UserData(user, true);
     });
 }
Пример #5
0
 public void UserData_ValidateUser_Constructor_3()
 {
     VoatAssert.Throws <ArgumentException>(() => {
         string user  = "******";
         var voatData = new Domain.UserData(user, true);
     });
 }
Пример #6
0
 public void UserData_ValidateUser_Constructor_2()
 {
     VoatAssert.Throws <ArgumentException>(() => {
         string user  = null;
         var voatData = new Domain.UserData(user, true);
     });
 }
Пример #7
0
        public ApiUserInfo UserInfo(string userName)
        {
            if (String.IsNullOrWhiteSpace(userName) || userName == "deleted" || (userName != "deleted" && !UserHelper.UserExists(userName)))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            ApiUserInfo userInfo = CacheHandler.Instance.Register <ApiUserInfo>(String.Format("Legacy:Api:UserInfo.{0}", userName),
                                                                                new Func <ApiUserInfo>(() =>
            {
                using (voatEntities db = new voatEntities(CONSTANTS.CONNECTION_READONLY))
                {
                    var resultModel = new ApiUserInfo();

                    var userData = new Domain.UserData(userName);
                    var info     = userData.Information;

                    resultModel.Name             = userName;
                    resultModel.CCP              = info.CommentPoints.Sum;
                    resultModel.LCP              = info.SubmissionPoints.Sum;
                    resultModel.RegistrationDate = info.RegistrationDate;
                    resultModel.Badges           = info.Badges.Select(badge => new ApiUserBadge {
                        Awarded = badge.CreationDate, BadgeName = badge.Name
                    }).ToList();

                    return(resultModel);
                }
            }), TimeSpan.FromMinutes(90));

            return(userInfo);
        }
Пример #8
0
 // GET: list of subverses user moderates
 //[OutputCache(Duration = 600, VaryByParam = "*")]
 public ActionResult SubversesUserModerates(string userName)
 {
     if (userName != null)
     {
         //This is expensive to hydrate the userData.Information for the moderation list
         var userData = new Domain.UserData(userName);
         return(PartialView("~/Views/Shared/Userprofile/_SidebarSubsUserModerates.cshtml", userData.Information.Moderates));
     }
     return(new EmptyResult());
 }
Пример #9
0
        public Domain.UserAccount UpdateUserData(long accountId, Domain.UserData newUserData)
        {
            var dbAccount = context.UserAccounts
                            .Include(ua => ua.UserData)
                            .SingleOrDefault(ua => ua.Id == accountId);

            if (dbAccount == null || dbAccount.UserData == null)
            {
                throw new AccountNotFoundException();
            }

            dbAccount.UserData.FirstName   = newUserData.FirstName;
            dbAccount.UserData.LastName    = newUserData.LastName;
            dbAccount.UserData.DateOfBirth = newUserData.DateOfBirth;
            dbAccount.UserData.Gender      = newUserData.Gender;

            context.SaveChanges();
            return(EntityMapper.ToDomainModel(dbAccount));
        }
        //// GET: subverse basic info used for V2 sets layout
        //public ActionResult SubverseBasicInfo(int setId, string subverseName)
        //{
        //    var userSetDefinition = _db.UserSetLists.FirstOrDefault(s => s.UserSetID == setId && s.Subverse.Equals(subverseName, StringComparison.OrdinalIgnoreCase));

        //    return PartialView("~/Views/AjaxViews/_SubverseInfo.cshtml", userSetDefinition);
        //}

        // GET: basic info about a user
        //[OutputCache(Duration = 600, VaryByParam = "*")]
        public ActionResult UserBasicInfo(string userName)
        {
            //acceptable constructor call
            var userData = new Domain.UserData(userName);
            var info     = userData.Information;

            var memberFor = Age.ToRelative(info.RegistrationDate);
            var scp       = info.SubmissionPoints.Sum;
            var ccp       = info.CommentPoints.Sum;

            var userInfoModel = new BasicUserInfo()
            {
                MemberSince = memberFor,
                Ccp         = ccp,
                Scp         = scp,
                Bio         = info.Bio
            };

            return(PartialView("~/Views/AjaxViews/_BasicUserInfo.cshtml", userInfoModel));
        }
Пример #11
0
        public static Database.Accounts.UserData ToDatabaseModel(Domain.UserData d)
        {
            if (d == null)
            {
                return(null);
            }

            return(new Database.Accounts.UserData
            {
                Id = d.Id,
                FirstName = d.FirstName,
                LastName = d.LastName,
                DateOfBirth = d.DateOfBirth,
                Gender = d.Gender,
                Pantry = ToDatabaseModel(d.Pantry),
                RecipeCatalog = ToDatabaseModel(d.RecipeCatalog),
                MealPlanCalendar = ToDatabaseModel(d.MealPlanCalendar),
                Tags = d.Tags?.Select(tag => ToDatabaseModel(tag))?.ToList() ?? null
            });
        }
Пример #12
0
        // return user statistics for user profile overview
        public static UserStatsModel UserStatsModel(string userName)
        {
            var loadFunc = new Func <UserStatsModel>(() =>
            {
                var userStatsModel = new UserStatsModel();

                using (var db = new VoatOutOfRepositoryDataContextAccessor())
                {
                    // 5 subverses user submitted to most
                    var subverses = db.Submission.Where(a => a.UserName == userName && !a.IsAnonymized && !a.IsDeleted)
                                    .GroupBy(a => new { a.UserName, a.Subverse })
                                    .Select(g => new SubverseStats {
                        SubverseName = g.Key.Subverse, Count = g.Count()
                    })
                                    .OrderByDescending(s => s.Count)
                                    .Take(5)
                                    .ToList();

                    // total comment count
                    var comments = db.Comment.Count(a => a.UserName == userName && !a.IsDeleted);

                    // voting habits
                    var userData = new Domain.UserData(userName);

                    var commentUpvotes      = userData.Information.CommentVoting.UpCount;
                    var commentDownvotes    = userData.Information.CommentVoting.DownCount;
                    var submissionUpvotes   = userData.Information.SubmissionVoting.UpCount;
                    var submissionDownvotes = userData.Information.SubmissionVoting.DownCount;

                    //var commentUpvotes = db.CommentVoteTrackers.Count(a => a.UserName == userName && a.VoteStatus == 1);
                    //var commentDownvotes = db.CommentVoteTrackers.Count(a => a.UserName == userName && a.VoteStatus == -1);
                    //var submissionUpvotes = db.SubmissionVoteTrackers.Count(a => a.UserName == userName && a.VoteStatus == 1);
                    //var submissionDownvotes = db.SubmissionVoteTrackers.Count(a => a.UserName == userName && a.VoteStatus == -1);

                    // get 3 highest rated comments
                    var highestRatedComments = db.Comment
                                               .Include(x => x.Submission)
                                               .Where(a => a.UserName == userName && !a.IsAnonymized && !a.IsDeleted)
                                               .OrderByDescending(s => s.UpCount - s.DownCount)
                                               .Take(3)
                                               .ToList();

                    // get 3 lowest rated comments
                    var lowestRatedComments = db.Comment
                                              .Include(x => x.Submission)
                                              .Where(a => a.UserName == userName && !a.IsAnonymized && !a.IsDeleted)
                                              .OrderBy(s => s.UpCount - s.DownCount)
                                              .Take(3)
                                              .ToList();

                    var linkSubmissionsCount    = db.Submission.Count(a => a.UserName == userName && a.Type == 2 && !a.IsDeleted && !a.IsAnonymized);
                    var messageSubmissionsCount = db.Submission.Count(a => a.UserName == userName && a.Type == 1 && !a.IsDeleted && !a.IsAnonymized);

                    // get 5 highest rated submissions
                    var highestRatedSubmissions = db.Submission.Where(a => a.UserName == userName && !a.IsAnonymized && !a.IsDeleted)
                                                  .OrderByDescending(s => s.UpCount - s.DownCount)
                                                  .Take(5)
                                                  .ToList();

                    // get 5 lowest rated submissions
                    var lowestRatedSubmissions = db.Submission.Where(a => a.UserName == userName && !a.IsAnonymized && !a.IsDeleted)
                                                 .OrderBy(s => s.UpCount - s.DownCount)
                                                 .Take(5)
                                                 .ToList();

                    userStatsModel.TopSubversesUserContributedTo = subverses;
                    userStatsModel.LinkSubmissionsSubmitted      = linkSubmissionsCount;
                    userStatsModel.MessageSubmissionsSubmitted   = messageSubmissionsCount;
                    userStatsModel.LowestRatedSubmissions        = lowestRatedSubmissions;
                    userStatsModel.HighestRatedSubmissions       = highestRatedSubmissions;
                    userStatsModel.TotalCommentsSubmitted        = comments;
                    userStatsModel.HighestRatedComments          = highestRatedComments;
                    userStatsModel.LowestRatedComments           = lowestRatedComments;

                    userStatsModel.TotalCommentsUpvoted      = commentUpvotes;
                    userStatsModel.TotalCommentsDownvoted    = commentDownvotes;
                    userStatsModel.TotalSubmissionsUpvoted   = submissionUpvotes;
                    userStatsModel.TotalSubmissionsDownvoted = submissionDownvotes;

                    ////HACK: EF causes JSON to StackOverflow on the highest/lowest comments because of the nested loading EF does with the include option, therefore null the refs here.
                    //highestRatedComments.ForEach(x => x.Submission.Comments = null);
                    //lowestRatedComments.ForEach(x => x.Submission.Comments = null);
                }

                return(userStatsModel);
            });

            var cachedData = CacheHandler.Instance.Register(CachingKey.UserOverview(userName), loadFunc, TimeSpan.FromMinutes(30));

            return(cachedData);
        }
Пример #13
0
 public void UserData_ValidateUser_Constructor_5()
 {
     string user     = "******";
     var    voatData = new Domain.UserData(user, true);
 }
Пример #14
0
 public void UserData_ValidateUser_Constructor_4()
 {
     string user     = "******";
     var    voatData = new Domain.UserData(user, true);
 }
Пример #15
0
 public void UserData_ValidateUser_Constructor_3()
 {
     string user     = "******";
     var    voatData = new Domain.UserData(user, true);
 }
Пример #16
0
 public void UserData_ValidateUser_Constructor_2()
 {
     string user     = null;
     var    voatData = new Domain.UserData(user, true);
 }