示例#1
0
        public async Task <IActionResult> Trades(string id)
        {
            UserCollectionViewModel model = new UserCollectionViewModel();
            //Gets the current user
            ApplicationUser currentUser = await GetCurrentUserAsync();

            //Finds the user we're looking at, using their username instead of an id (see the Profile method for an explanation why)
            model.ViewedUser = await _userManager.Users.FirstOrDefaultAsync(user => user.UserName == id);

            //If we can't find the desired user, throw a NotFound page
            if (model.ViewedUser == null)
            {
                return(NotFound());
            }

            //Sets a boolean to true if the user is viewing their own profile
            if (currentUser.UserName == id)
            {
                model.isOwnProfile = true;
            }

            //Fetches all the Pokemon we'll be looking at. In this case, it's Pokemon from a specific user that have been marked as "Open to Trade"
            model.ViewedCollection = await _context.CaughtPokemon
                                     .Include(cp => cp.User)
                                     .Include(cp => cp.Gender)
                                     .Include(cp => cp.Pokemon)
                                     .Where(cp => cp.User.UserName == id)
                                     .Where(cp => cp.isHidden == false)
                                     .Where(cp => cp.isOwned == true)
                                     .Where(cp => cp.isTradeOpen == true)
                                     .OrderBy(cp => cp.PokemonId)
                                     .ToListAsync();

            //Gets a list of all the Pokemon the currently logged in user has caught (and have not been soft-deleted)
            List <CaughtPokemon> listOfUserCaughtPokemon = await _context.CaughtPokemon
                                                           .Where(cp => cp.UserId == currentUser.Id)
                                                           .Where(cp => cp.isOwned == true)
                                                           .Where(cp => cp.isHidden == false)
                                                           .ToListAsync();

            //Loops through the list of Pokemon the user owns, so that we can get their IDs. Again, this is to highlight Pokemon the user owns
            foreach (CaughtPokemon caughtPokemon in listOfUserCaughtPokemon)
            {
                //If this list does not already contain the species of Pokemon we're currently looking at...
                if (!model.CurrentUserCollection.Contains(caughtPokemon.PokemonId))
                {
                    //...add it to the list of IDs
                    model.CurrentUserCollection.Add(caughtPokemon.PokemonId);
                }
            }

            //Returns our completed ViewModel to our View
            return(View(model));
        }
        public ActionResult Index()
        {
            UserManager             manager = new UserManager();
            UserCollectionViewModel model   = manager.GetUserList(new UserCollectionViewModel
            {
                SearchUserStatus = 1
            });

            model.SearchUserStatus = 1;

            return(View(model));
        }
        public ActionResult List(string username, int role, int status)
        {
            UserManager manager = new UserManager();

            UserCollectionViewModel model = new UserCollectionViewModel
            {
                SearchUsername   = username,
                SearchUserRole   = role,
                SearchUserStatus = status
            };

            model = manager.GetUserList(model);

            return(PartialView("List", model));
        }
示例#4
0
        public async Task <IActionResult> Favorites(string id)
        {
            UserCollectionViewModel model = new UserCollectionViewModel();
            //Gets the current user
            ApplicationUser currentUser = await GetCurrentUserAsync();

            //Finds the user we're viewing, using a username instead of an id (for details on this, view my Profile method above)
            model.ViewedUser = await _userManager.Users.FirstOrDefaultAsync(user => user.UserName == id);

            if (model.ViewedUser == null)
            {
                return(NotFound());
            }

            //Fetches all Pokemon owned by the user we're looking at, that are also marked as a favorite
            model.ViewedCollection = await _context.CaughtPokemon
                                     .Include(cp => cp.User)
                                     .Include(cp => cp.Gender)
                                     .Include(cp => cp.Pokemon)
                                     .Where(cp => cp.User.UserName == id)
                                     .Where(cp => cp.isHidden == false)
                                     .Where(cp => cp.isOwned == true)
                                     .Where(cp => cp.isFavorite == true)
                                     .OrderBy(cp => cp.PokemonId)
                                     .ToListAsync();

            //Gets a list of all the Pokemon the currently logged in user has caught (and have not been soft-deleted)
            List <CaughtPokemon> listOfUserCaughtPokemon = await _context.CaughtPokemon
                                                           .Where(cp => cp.UserId == currentUser.Id)
                                                           .Where(cp => cp.isOwned == true)
                                                           .Where(cp => cp.isHidden == false)
                                                           .ToListAsync();

            //Loops through the list of Pokemon the user owns, so that we can get their IDs. Again, this is to highlight Pokemon the user owns
            foreach (CaughtPokemon caughtPokemon in listOfUserCaughtPokemon)
            {
                //If this list does not already contain the species of Pokemon we're currently looking at...
                if (!model.CurrentUserCollection.Contains(caughtPokemon.PokemonId))
                {
                    //...add it to the list of IDs
                    model.CurrentUserCollection.Add(caughtPokemon.PokemonId);
                }
            }

            //Sends the completed ViewModel to our View
            return(View(model));
        }
        public UserCollectionViewModel GetUserList(UserCollectionViewModel model = null)
        {
            if (model == null) model = new UserCollectionViewModel();

            // Get data
            var query = _unitOfWork.GetRepository<Mst_Credential>().GetQueryable();

            // Set Where cause
            if (!string.IsNullOrWhiteSpace(model.SearchUsername))
                query = query.Where(o => o.Username.StartsWith(model.SearchUsername));

            if (model.SearchUserStatus != null && model.SearchUserStatus >= 0)
                query = query.Where(o => o.Status == model.SearchUserStatus);

            if (model.SearchUserRole != null && model.SearchUserRole >= 0)
                query = query.Where(o => o.Role == model.SearchUserRole);

            // Mapping dto with model
            model.UserCollection = query.Select(o => new UserModel()
            {
                UserId = o.UserId,
                UserCode = o.UserCode,
                Username = o.Username,
                Role = o.Role,
                Status = o.Status
            }).ToList();

            // Set Lookup
            model.LookupUserStatus = Helper.LookupUserStatus;
            model.LookupRole = Helper.LookupRole;

            // Mapping Id with lookup name
            for (int i = 0; i < model.UserCollection.Count; i++)
            {
                UserModel user = model.UserCollection[i];

                user.RoleName = Helper.GetNameFromLookup(user.Role, model.LookupRole);
                user.StatusName = Helper.GetNameFromLookup(user.Status, model.LookupUserStatus);

                model.UserCollection[i] = user;
            }

            return model;
        }
示例#6
0
        public IActionResult Userguidecollection()
        {
            UserProfiles profile = _context.UserProfiles.FirstOrDefault(id =>
                                                                        id.UserAccountId == _userManager.GetUserId(User));

            UserCollectionViewModel userguidecollection = new UserCollectionViewModel();

            userguidecollection.userGuidesColletions = _context.UserGuidesColletion.Where(from => from.UserProfilesId == profile.Id).ToList();

            List <Guides> fromList = new List <Guides>();

            foreach (var g in userguidecollection.userGuidesColletions)
            {
                fromList.Add(_context.Guides.FirstOrDefault(from => from.Id == g.UserProfilesId));
            }

            userguidecollection.guides = fromList;
            return(View(userguidecollection));
        }