Exemple #1
0
        // GET: Dashboard
        public async Task <ActionResult> Index()
        {
            var currentUser = await GetCurrentUser();

            var pendingRewardDonation = _rewardDonationRepository.GetAll()
                                        .Include(d => d.ToUser)
                                        .FirstOrDefault(d => d.FromUserId == AbpSession.UserId.Value &&
                                                        d.Status == Status.Pending);

            var viewModel = new DashboardViewModel
            {
                PendingRewardDonation = pendingRewardDonation,
                CurrentUser           = currentUser,
                Transactions          = _donationRepository.GetTransactions(AbpSession.UserId.Value),
                PendingDonation       =
                    _donationRepository.GetAll()
                    .Include(d => d.ToUser)
                    .FirstOrDefault(d => d.FromUserId == AbpSession.UserId.Value &&
                                    d.Status == Status.Pending),
                PendingPackage = _packageRepository.FirstOrDefault(p => p.UserId == AbpSession.UserId.Value &&
                                                                   p.Status != Status.PaidOut),
                PendingConfirmations         = _donationRepository.GetPendingConfirmations(AbpSession.UserId.Value),
                Downlines                    = _referralRepository.GetAll().Where(r => r.UserId == AbpSession.UserId.Value).Select(r => r.Downline).ToList(),
                ReferralPendingConfirmations = _rewardDonationRepository.GetPendingConfirmations(AbpSession.UserId.Value)
            };

            if (viewModel.PendingPackage != null && viewModel.PendingPackage.Status == Status.Pending)
            {
                FlashSuccess("You have a pendnig package. Please hold on for the system to pair you");
            }

            return(View(viewModel));
        }
Exemple #2
0
        public OutputResultDto ConfirmDonation(ConfirmDonationInput input)
        {
            if (input.Type == "r")
            {
                return(ConfirmRewardDonation(input));
            }
            var donation = _donationRepository.FirstOrDefault(d => d.Id == input.DonationId &&
                                                              d.ToUserId == input.CurrentUserId);

            if (donation == null)
            {
                return(new OutputResultDto {
                    Message = "Invalid Donation ID"
                });
            }
            donation.Status = Status.PaidOut;
            _donationRepository.Update(donation);
            var ticket = _ticketRepository.FirstOrDefault(t => t.Id == donation.TicketId);

            //mark the ticket as paid out
            ticket.Status = Status.PaidOut;
            _ticketRepository.InsertOrUpdateAndGetId(ticket);

            //if there is no other package that have not been paid out for this package, then mark the package as paid out
            if (_ticketRepository.FirstOrDefault(t => t.Id != ticket.Id && t.PackageId == ticket.PackageId &&
                                                 t.Status != Status.PaidOut) == null)
            {
                var package = _packageRepository.Get(ticket.PackageId);
                package.Status = Status.PaidOut;
                _packageRepository.Update(package);
            }

            //create tickets for the package
            //if the actual donation for this package have been confirmed create tickets for the package
            if (_rewardDonationRepository.GetAll().Any(d => d.PackageId == donation.PackageId && d.Status == Status.PaidOut))
            {
                var result = CreateDonationTicket(new CreateDonationTicketInput {
                    PackageId = donation.PackageId
                });
                if (!result.Success)
                {
                    //todo log ticket creation error
                }
            }
            return(new OutputResultDto {
                Message = "Thanks for confirming the donation", Success = true
            });
        }