Beispiel #1
0
        public void MakeDonation(KudosBasketDonationDTO donation)
        {
            lock (donateLock)
            {
                var user = _usersDbSet
                           .First(usr => usr.Id == donation.UserId);
                var basket = _kudosBasketsDbSet
                             .Include(b => b.KudosLogs)
                             .First(b => b.OrganizationId == donation.OrganizationId);

                _kudosBasketValidator.CheckIfBasketIsActive(basket);
                _kudosBasketValidator.CheckIfUserHasEnoughKudos(user.RemainingKudos, donation.DonationAmount);

                var otherType = _kudosTypesDbSet
                                .First(type => type.Type == ConstBusinessLayer.KudosTypeEnum.Other);
                var minusType = _kudosTypesDbSet
                                .First(type => type.Type == ConstBusinessLayer.KudosTypeEnum.Minus);

                var logComment = string.Format(Resources.Widgets.KudosBasket.KudosBasket.KudosBasketDonationComment, basket.Title);
                var noUser     = default(string);

                var plusLog  = CreateKudosLogForBasket(donation, otherType, logComment, user.Id);
                var minusLog = CreateKudosLogForBasket(donation, minusType, logComment, noUser);

                _kudosLogsDbSet.Add(minusLog);
                basket.KudosLogs.Add(plusLog);

                _uow.SaveChanges(false);

                _kudosService.UpdateProfileKudos(user, donation);
            }
        }
Beispiel #2
0
        public void Should_Update_User_Profile_Kudos_Depending_On_Logs()
        {
            var user = new ApplicationUser()
            {
                Id             = "Id",
                EmploymentDate = DateTime.UtcNow.AddDays(-10)
            };

            var userOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 1,
                UserId         = "userId"
            };

            MockKudosLogsForProfileUpdate();

            _kudosService.UpdateProfileKudos(user, userOrg);
            Assert.AreEqual(11, user.TotalKudos);
            Assert.AreEqual(9, user.RemainingKudos);
            Assert.AreEqual(2, user.SpentKudos);
        }