public PaginatedList <PendingAccessRequest> Pending(Guid organizationId)
        {
            PaginatedList <PendingAccessRequest> pending = new PaginatedList <PendingAccessRequest>();
            var accessRequests = _accessRequestRepo.Find(organizationId, ar => ar.IsAccessRequested.HasValue && ar.IsAccessRequested.Value, ar => ar.AccessRequestedOn, OrderByDirectionType.Descending);

            foreach (AccessRequest request in accessRequests.Items)
            {
                if (request.Id.HasValue && request.PersonId.HasValue)
                {
                    PendingAccessRequest par = new PendingAccessRequest
                    {
                        Id = request.Id
                    };
                    var person = _personRepo.GetOne(request.PersonId.Value);
                    par.Name = person.Name;

                    var email = _personEmailRepository.Find(null, p => p.PersonId == request.PersonId.Value && p.IsPrimaryEmail == true)?.Items?.FirstOrDefault()?.Address;

                    if (email == null)
                    {
                        email = _emailVerificationRepository.Find(null, ev => ev.PersonId == request.PersonId.Value)?.Items?.FirstOrDefault()?.Address;
                    }
                    par.Email = email;
                    pending.Add(par);
                }
            }
            pending.TotalCount = pending.Items.Count;
            pending.ParentId   = organizationId;

            return(pending);
        }
Пример #2
0
        public PaginatedList <UserCardModel> GetUserFollowings(string userName, int pageIndex, int pageSize, string currUserId)
        {
            PaginatedList <UserCardModel> ret = new PaginatedList <UserCardModel>();
            UserInfo user = _context.Set <UserInfo>().AsNoTracking().FirstOrDefault(p => p.UName == userName);
            Dictionary <string, FollowState> currentUserFollowInfo = _userFollowCacheService.GetFollowingUserIds(currUserId);

            // If cache not holding current user follow info get from database and set cache
            if (currentUserFollowInfo == null)
            {
                currentUserFollowInfo = _context.SetChild <FollowInfo>().AsNoTracking().Where(p => p.FollowerId == currUserId).Select(p => new { p.FollowedId, p.FollowState }).ToDictionary(t => t.FollowedId, t => t.FollowState);;
                _userFollowCacheService.SetFollowingUserIds(currUserId, currentUserFollowInfo, 60);
            }

            // If Current User is not following the user dont return data and user is not self
            if (!currentUserFollowInfo.Any(p => p.Key == user.AppUserId && p.Value == FollowState.Confirmed) && currUserId != user.AppUserId)
            {
                return(ret);
            }

            // Get Followed User Ids
            List <string> followedUserIds = _context.SetChild <FollowInfo>().AsNoTracking()
                                            .Where(p => p.FollowerId == user.AppUserId && p.FollowState == FollowState.Confirmed)
                                            .OrderByDescending(p => p.DateUtcFollowed)
                                            .Skip((pageIndex - 1) * pageSize)
                                            .Take(pageSize).Select(p => p.FollowedId).ToList();
            // Get Followed User Count
            int totalCount = _userFollowCacheService.GetUserFollowingCount(user.AppUserId) ??
                             _context.SetChild <FollowInfo>().AsNoTracking().Where(p => p.FollowerId == user.AppUserId && p.FollowState == FollowState.Confirmed).Count();

            // Get User Data From Database
            IQueryable <UserCardModel> userCards = _context.Set <UserInfo>().AsNoTracking().Where(p => followedUserIds.Contains(p.AppUserId))
                                                   .Select(p => new UserCardModel()
            {
                AppUserId    = p.AppUserId,
                ProfileImage = _userProfileImageSettings.UserImageUrlTemplate.Replace("{#appUserId}", p.AppUserId),
                Username     = p.UName,
            });

            // Get Total Reputation
            foreach (var item in userCards)
            {
                item.Reputation = _userCacheService.GetUserReputation(item.AppUserId) ?? GetUserReputation(item.AppUserId, 1200);
                // Check if the current user follows the users fetched from database
                var followState = currentUserFollowInfo.SingleOrDefault(p => p.Key == item.AppUserId);
                item.FollowState = followState.Key == null ? FollowState.Unfollowed : followState.Value;
                ret.Add(item);
            }


            // return as paginated
            return(ret.ToPaginatedList(pageIndex, pageSize, totalCount));
        }
Пример #3
0
        public PaginatedList <OrganizationCard> PendingOrganizationAccess(Guid personId)
        {
            PaginatedList <OrganizationCard> cards = new PaginatedList <OrganizationCard>();

            _accessRequestRepo.ForceIgnoreSecurity();
            var accessRequests = _accessRequestRepo.Find(null, ar => ar.IsAccessRequested.HasValue && ar.IsAccessRequested.Value && ar.PersonId == personId, ar => ar.AccessRequestedOn, OrderByDirectionType.Descending);

            _accessRequestRepo.ForceSecurity();
            var orgIds = accessRequests.Items.Select(om => om.OrganizationId).Distinct().ToArray();

            if (orgIds.Length > 0)
            {
                var orgs = _organizationRepo.Find(null, o => orgIds.Contains(o.Id), o => o.Name, OrderByDirectionType.Ascending);

                foreach (Organization org in orgs.Items)
                {
                    OrganizationCard card = new OrganizationCard
                    {
                        Id                   = org.Id.Value,
                        Name                 = org.Name,
                        CreatedOn            = org.CreatedOn,
                        IsOrganizationMember = false
                    };
                    //card.CanLeave = true;
                    //var orgMem = orgMems.Items.Where(om => om.OrganizationId == org.Id).FirstOrDefault();
                    //if (orgMem != null)
                    //{
                    //    card.JoinedOn = orgMem.CreatedOn;
                    //    if (orgMem.IsAdministrator.HasValue && orgMem.IsAdministrator.Value)
                    //        card.CanDelete = true;
                    //}
                    Guid creatorPersonId = Guid.Empty;
                    if (Guid.TryParse(org.CreatedBy, out creatorPersonId))
                    {
                        Person creatorPerson = _personRepo.GetOne(creatorPersonId);
                        if (creatorPerson != null)
                        {
                            card.CreatedBy = string.Format("{0}", creatorPerson.Name);
                        }
                    }
                    if (string.IsNullOrEmpty(card.CreatedBy))
                    {
                        card.CreatedBy = org.CreatedBy;
                    }

                    cards.Add(card);
                }
            }

            return(cards);
        }
Пример #4
0
        public void Setup()
        {
            items.Add(new Item {
                Id = 1L, Name = "Item1", Description = "Item1 Description", Price = 100, Stock = 10, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
            });
            items.Add(new Item {
                Id = 2L, Name = "Item2", Description = "Item2 Description", Price = 200, Stock = 5, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
            });
            items.Add(new Item {
                Id = 3L, Name = "Item3", Description = "Item3 Description", Price = 300, Stock = 50, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
            });
            items.Add(new Item {
                Id = 4L, Name = "Item4", Description = "Item4 Description", Price = 250, Stock = 15, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
            });
            items.Add(new Item {
                Id = 5L, Name = "Item5", Description = "Item5 Description", Price = 400, Stock = 105, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
            });

            repository = new Mock <IBaseRepository <Item> >();
            repository.Setup(mr => mr.GetAsync(null, null)).ReturnsAsync(items);

            repository.Setup(mr => mr.Update(It.IsAny <Item>())).Callback <Item>(((i) => items[0].Stock = i.Stock));

            repository.Setup(mr => mr.GetAsync(It.IsAny <object>())).Returns((Int64 id) =>
            {
                return(Task.FromResult(
                           (from item in items
                            where item.Id == id
                            select item).FirstOrDefault()
                           ));
            });

            var unitOfwork = new Mock <IUnitOfWork>();

            service = new BaseService <Item>(repository.Object, unitOfwork.Object);
        }
        public async Task <IActionResult> GetFileFolder(string id, string driveName = null)
        {
            try
            {
                var fileFolder = _manager.GetFileFolder(id, driveName);

                var list = new PaginatedList <FileFolderViewModel>();
                list.Add(fileFolder);
                list.PageSize   = 0;
                list.PageNumber = 0;
                list.TotalCount = 1;

                return(Ok(list));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Пример #6
0
        public async Task <IActionResult> GetDetailsView(Guid id)
        {
            try
            {
                var log = _repository.GetOne(id);

                string name = _repository.GetServiceName(log);

                var logView = new AuditLogDetailsViewModel();
                logView             = logView.Map(log);
                logView.ServiceName = name;

                PaginatedList <AuditLogDetailsViewModel> logList = new PaginatedList <AuditLogDetailsViewModel>();
                logList.Add(logView);

                return(Ok(logList));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
        // GET:
        public async Task <IActionResult> ListBars(string sortOrder, int?pageNumber)
        {
            try
            {
                var listVM = new ListBarsViewModel();
                listVM.CurrentSortOrder = sortOrder;
                listVM.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
                listVM.RatingSortParm   = sortOrder == "Rating" ? "rating_asc" : "Rating";
                var bars = await _barServices.GetAllBars(pageNumber, sortOrder);

                if (bars.Count == 0)
                {
                    _toast.AddInfoToastMessage("There are no more cocktails!");
                }
                var pagList = new PaginatedList <BarViewModel>()
                {
                    PageIndex  = bars.PageIndex,
                    TotalPages = bars.TotalPages
                };
                foreach (var item in bars)
                {
                    pagList.Add(item.MapBarToVM());
                }
                listVM.AllBars = pagList;
                if (bars.PageIndex == 1)
                {
                    return(View(listVM));
                }
                return(PartialView("_BarPaginationPartial", listVM));
            }
            catch (Exception ex)
            {
                _toast.AddErrorToastMessage(ex.Message);
                ViewBag.ErrorTitle = "";
                return(View("Error"));
            }
        }
        public PaginatedList <TeamMemberViewModel> GetPeopleInOrganization(Guid organizationId, string sortColumn, OrderByDirectionType direction = OrderByDirectionType.Ascending, int skip = 0, int take = 100)
        {
            PaginatedList <TeamMemberViewModel> team = new PaginatedList <TeamMemberViewModel>
            {
                ParentId = organizationId
            };

            var org = _organizationRepo.GetOne(organizationId);

            if (org == null)
            {
                throw new KeyNotFoundException();
            }

            bool   orgHasEmailDomain = false;
            string emailDomainWithAt = string.Empty;

            var members = _organzationMemberRepo.Find(organizationId);

            team.TotalCount = members.Items.Count;

            var personIds = members.Items.Select(om => om.PersonId).Distinct().ToArray();

            var people = _personRepo.Find(null, p => personIds.Contains(p.Id));
            var emails = _emailVerificationRepository.Find(null, e => personIds.Contains(e.PersonId));

            foreach (OrganizationMember member in members.Items.Skip(skip).Take(take))
            {
                TeamMemberViewModel teamMember = new TeamMemberViewModel
                {
                    OrganizationMemberId = member.Id.Value,
                    PersonId             = member.PersonId.Value,
                    JoinedOn             = member.CreatedOn.Value,
                    InvitedBy            = member.InvitedBy,
                    IsAdmin = member.IsAdministrator.GetValueOrDefault(false)
                };

                var person = people.Items.Where(p => p.Id.Equals(member.PersonId)).FirstOrDefault();
                if (person != null)
                {
                    teamMember.UserName = person.Name;
                    teamMember.Name     = person.Name;
                    teamMember.Status   = "InActive";
                    if (orgHasEmailDomain)
                    {
                        var matchingEmailList     = emails.Items.Where(e => e.PersonId.Equals(member.PersonId) && e.Address.EndsWith(emailDomainWithAt)).ToList();
                        var orderedList           = matchingEmailList.OrderBy(x => x.CreatedOn);
                        var correctEmailForMember = orderedList.FirstOrDefault();

                        if (correctEmailForMember != null)
                        {
                            teamMember.EmailAddress = correctEmailForMember.Address;
                            teamMember.Status       = correctEmailForMember.IsVerified.GetValueOrDefault(false) ? "Active" : "InActive";
                        }
                    }
                    if (string.IsNullOrEmpty(teamMember.EmailAddress))
                    {
                        var matchingEmailList     = emails.Items.Where(e => e.PersonId.Equals(member.PersonId)).ToList();
                        var orderedList           = matchingEmailList.OrderBy(x => x.CreatedOn);
                        var correctEmailForMember = orderedList.FirstOrDefault();

                        if (correctEmailForMember != null)
                        {
                            teamMember.EmailAddress = correctEmailForMember.Address;
                            teamMember.Status       = correctEmailForMember.IsVerified.GetValueOrDefault(false) ? "Active" : "InActive";
                        }
                    }
                }

                team.Add(teamMember);
            }

            if (!string.IsNullOrWhiteSpace(sortColumn))
            {
                if (direction == OrderByDirectionType.Ascending)
                {
                    team.Items = team.Items.OrderBy(t => t.GetType().GetProperty(sortColumn).GetValue(t)).ToList();
                }
                else if (direction == OrderByDirectionType.Descending)
                {
                    team.Items = team.Items.OrderByDescending(t => t.GetType().GetProperty(sortColumn).GetValue(t)).ToList();
                }
            }

            return(team);
        }
        public PaginatedList <OrganizationCard> MyOrganizations(Guid personId, bool IncludeAccessRequestedOrg = false)
        {
            _organzationMemberRepo.ForceIgnoreSecurity();
            var orgMems = _organzationMemberRepo.Find(null, om => om.PersonId.Equals(personId));
            var orgIds  = orgMems.Items.Select(om => om.OrganizationId).Distinct().ToArray();
            var orgs    = _organizationRepo.Find(null, o => orgIds.Contains(o.Id));

            _organzationMemberRepo.ForceSecurity();


            PaginatedList <OrganizationCard> cards = new PaginatedList <OrganizationCard>();

            foreach (Organization org in orgs.Items)
            {
                OrganizationCard card = new OrganizationCard
                {
                    Id        = org.Id.Value,
                    Name      = org.Name,
                    CreatedOn = org.CreatedOn,
                    CanLeave  = true
                };
                var orgMem = orgMems.Items.Where(om => om.OrganizationId == org.Id).FirstOrDefault();
                if (orgMem != null)
                {
                    card.JoinedOn             = orgMem.CreatedOn;
                    card.IsOrganizationMember = true;
                    if (orgMem.IsAdministrator.HasValue && orgMem.IsAdministrator.Value)
                    {
                        card.CanDelete = true;
                    }
                }
                Guid creatorPersonId = Guid.Empty;
                if (Guid.TryParse(org.CreatedBy, out creatorPersonId))
                {
                    Person creatorPerson = _personRepo.GetOne(creatorPersonId);
                    if (creatorPerson != null)
                    {
                        card.CreatedBy = string.Format("{0}", creatorPerson.Name);
                    }
                }
                if (string.IsNullOrEmpty(card.CreatedBy))
                {
                    card.CreatedBy = org.CreatedBy;
                }


                cards.Add(card);
            }

            if (IncludeAccessRequestedOrg)
            {
                //organizations requested for access
                var accessRequest = PendingOrganizationAccess(personId);
                if (accessRequest?.Items?.Count > 0)
                {
                    cards.Items.AddRange(accessRequest.Items);
                }
            }

            cards.ParentId   = personId;
            cards.TotalCount = cards.Items.Count;
            return(cards);
        }