public ActionResult CategoryPage()
        {
            var userid = User.Identity.GetUserId();

            if (userid == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var viewmodel = new FriendIndexViewModel();
            var ctx       = new MVCDbContext();
            var profiles  = new List <Profile>();

            //Kollar om variabeln existerar ännu, och isåfall ta ut värdet därifrån.
            if (Session["categorySaved"] != null)
            {
                var chosencategory = (Session["categorySaved"]).ToString();
                viewmodel.Category = chosencategory;
                //Hämtar ut de kategori-rader som har den specifika kategorin
                var categories = ctx.Category.Where(c => c.CategoryName == chosencategory).ToList();
                foreach (var c in categories)
                {
                    //Plockar ut profilerna som finns i category-tabellen och den som kategoriserat dem är användaren.
                    if (c.CategorizerId.Equals(userid))
                    {
                        var profile = ctx.Profile.FirstOrDefault(p => p.ProfileId == c.TheCategorizedId);
                        profiles.Add(profile);
                    }
                }
            }
            profiles.RemoveAll(x => x.IsActive == false);
            viewmodel.Profiles = profiles;

            return(View(viewmodel));
        }
        public ActionResult ReturnItems(FriendIndexViewModel model)
        {
            //Lagrar kategorin i en variabel som kan användas i metoden ovanför.
            Session["categorySaved"] = model.Category;

            return(RedirectToAction("CategoryPage", "FriendList"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Index(string firstName, string lastName, string pseudonym, string telephone,
                                                string email, string address, string city, string postalCode, int currentPage = 1, string sortBy = "Id")
        {
            List <Friend> friendList = await FriendRepo.GetPage(currentPage, 5, sortBy);

            if (!string.IsNullOrEmpty(firstName))
            {
                friendList = friendList.Where(f => f.FirstName.Contains(firstName)).ToList();
            }

            if (!string.IsNullOrEmpty(lastName))
            {
                friendList = friendList.Where(l => l.LastName.Contains(lastName)).ToList();
            }

            if (!string.IsNullOrEmpty(pseudonym))
            {
                friendList = friendList.Where(p => p.Pseudonym.Contains(pseudonym)).ToList();
            }

            if (!string.IsNullOrEmpty(telephone))
            {
                friendList = friendList.Where(t => t.Telephone.Contains(telephone)).ToList();
            }

            if (!string.IsNullOrEmpty(email))
            {
                friendList = friendList.Where(e => e.Email.Contains(email)).ToList();
            }

            if (!string.IsNullOrEmpty(address))
            {
                friendList = friendList.Where(a => a.Address.Contains(address)).ToList();
            }

            if (!string.IsNullOrEmpty(city))
            {
                friendList = friendList.Where(c => c.City.Contains(city)).ToList();
            }

            if (!string.IsNullOrEmpty(postalCode))
            {
                friendList = friendList.Where(p => p.PostalCode.Contains(postalCode)).ToList();
            }

            FriendIndexViewModel friendIndexViewModel = new FriendIndexViewModel()
            {
                Friends = friendList,
                Count   = await FriendRepo.GetCount(),
                SortBy  = sortBy
            };

            return(View(friendIndexViewModel));
        }
        // GET: FriendList
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var ctx = new MVCDbContext();

            var profileActive = ctx.Profile.FirstOrDefault(p => p.ProfileId == userId);

            if (!profileActive.IsActive)
            {
                return(RedirectToAction("EditProfileData", "Profile"));
            }

            var viewmodel = new FriendIndexViewModel();

            //Fyller listan med de rader där användaren är den som kategoriserar.
            viewmodel.Categories = ctx.Category.Where(p => p.CategorizerId == userId).ToList();
            viewmodel.Relations  = ctx.Relation.ToList();
            var friendList = new List <Profile>();

            foreach (var r in viewmodel.Relations)
            {
                if (r.UserId.Equals(userId) || r.FriendId.Equals(userId))
                {
                    //Lägger till de profiler som personen har en relation med.
                    var profile = ctx.Profile.FirstOrDefault(
                        p => (p.ProfileId == r.FriendId || p.ProfileId == r.UserId) && (p.ProfileId != userId));
                    friendList.Add(profile);
                }
            }

            friendList.RemoveAll(x => x.IsActive == false);

            viewmodel.Profiles = friendList;

            return(View(viewmodel));
        }