public async Task <IActionResult> Index()
        {
            var userIdClaim = User
                              .Claims
                              .FirstOrDefault(c => c.Type.Equals("sub") && c.Issuer.Equals("https://localhost:5001"));

            var nameClaim = User
                            .Claims
                            .FirstOrDefault(c => c.Type.Equals("name") && c.Issuer.Equals("https://localhost:5001"));

            if (userIdClaim == null && nameClaim != null)
            {
                return(Unauthorized());
            }

            var user    = Guid.Parse(userIdClaim.Value);
            var history =
                await _paymentsService.GetTransactionHistoryAsync(user);

            history =
                history.OrderByDescending(t => t.Date)
                .ToList();

            ViewBag.User           = nameClaim.Value;
            ViewBag.AccountHistory = history;
            ViewBag.AccountBalance =
                await _paymentsService.GetBalanceAsync(user);

            return(View());
        }
Example #2
0
        /// <summary>
        /// Gets Values to display on User Dashboard
        /// </summary>
        /// <param name="user"></param>
        /// <returns>
        /// ExternalUserDashboardRequestDto
        /// </returns>
        public async Task <ExternalUserDashboardRequestDto> GetUserDashBoardValuesAsync(Guid user)
        {
            ExternalUserDashboardRequestDto dto = new ExternalUserDashboardRequestDto();

            // User account balance
            dto.AccountBalance = await _paymentsService.GetBalanceAsync(user);

            // All applications by user
            var applicationsByUser = await _mapper
                                     .ProjectTo <SubmittedApplicationSummaryResponseDto>(
                _context.Applications
                .Include(a => a.PrivateEntity)
                .Where(a => a.Status != EApplicationStatus.Incomplete && a.User == user)
                .OrderByDescending(a => a.DateSubmitted)
                .Take(10))
                                     .ToListAsync();

            if (applicationsByUser.Count > 0)
            {
                // Submitted application count
                dto.SubmittedApplicationsCount = applicationsByUser.Count;

                //Account Use HttpService

                // Recent Activity
                dto.RecentActivity = applicationsByUser.Take(10);

                // Approved applications
                // var examinedNameSearches = await _mapper
                //     .ProjectTo<SubmittedApplicationSummaryResponseDto>(_context.Applications
                //         .Include(a => a.NameSearch)
                //         .ThenInclude(n => n.Names)
                //         .Where(a => a.Service.Equals(EService.NameSearch) && a.Status == EApplicationStatus.Examined)).ToListAsync();

                var examinedNameSearches = await _context.Applications
                                           .Include(a => a.NameSearch)
                                           .ThenInclude(n => n.Names)
                                           .Where(a => a.Service.Equals(EService.NameSearch) && a.Status == EApplicationStatus.Examined)
                                           .OrderByDescending(a => a.DateSubmitted)
                                           .ToListAsync();

                var approvedNamesSearches = new List <SubmittedApplicationSummaryResponseDto>();
                foreach (var examinedNameSearch in examinedNameSearches)
                {
                    try
                    {
                        var approvedName =
                            examinedNameSearch.NameSearch.Names.Single(n =>
                                                                       n.Status == ENameStatus.Reserved || n.Status == ENameStatus.Used);
                        if (approvedName != null)
                        {
                            approvedNamesSearches.Add(
                                _mapper.Map <SubmittedApplicationSummaryResponseDto>(examinedNameSearch));
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        // throw;
                    }
                }

                var approvedEntities = await _mapper
                                       .ProjectTo <SubmittedApplicationSummaryResponseDto>(_context.Applications
                                                                                           .Include(a => a.PrivateEntity)
                                                                                           .Where(a => a.Service == EService.PrivateLimitedCompany &&
                                                                                                  a.Status == EApplicationStatus.Approved))
                                       .ToListAsync();


                dto.ApprovedApplications = approvedNamesSearches.Concat(approvedEntities);
                dto.ApprovedApplications = dto.ApprovedApplications.OrderBy(a => a.DateSubmitted);

                // Registered Entities count
                dto.RegisteredEntitiesCount = approvedEntities.Count;
            }

            return(dto);
        }