Ejemplo n.º 1
0
        // GET: Search

        public ActionResult Index(string query, string category)
        {
            ViewSearchModel model = new ViewSearchModel
            {
                Query  = "" + query,
                Target = "" + category
            };

            using (PixurfDBContext db = new PixurfDBContext())
            {
                //Retrieve Users
                if (category == null || category.Equals("People") || category.Equals("All"))
                {
                    var queryable = db.Users.Where(user => user.Name.Contains(query) ||
                                                   (query.Contains("@") && user.Email.Contains(query)));
                    UserRelationship relationship = new UserRelationship();
                    foreach (User user in queryable)
                    {
                        model.Users.Add(new ViewPeopleSearch {
                            Id = user.User_ID, Name = user.Name, Email = user.Email, NoofFollowers = relationship.NoOfFollowers(user.User_ID)
                        });

                        if (model.Users.Count >= 5)
                        {
                            break;
                        }
                    }
                }
                //Retrieve Contents
                if (category == null || category.Equals("Content") || category.Equals("All"))
                {
                    var queryable = db.Contents.Where(c => c.Title.Contains(query) || c.Description.Contains(query));

                    foreach (Content content in queryable)
                    {
                        bool add = false;
                        if (content.Access == "Public")
                        {
                            add = true;
                        }
                        else if (User.Identity.IsAuthenticated)
                        {
                            string uid = User.Identity.GetUserId();

                            if (content.User_ID.Equals(uid))
                            {
                                add = true;
                            }
                            else
                            {
                                UserRelationship relationship = new UserRelationship();
                                if (content.Access == "Follower" && relationship.Following(content.User_ID, uid))
                                {
                                    add = true;
                                }
                                // if not blocked
                                // lol..... what about non logged in users :P
                            }
                        }
                        if (add)
                        {
                            model.Contents.Add(new ViewContentSearch {
                                Id = content.Content_ID, Title = content.Title, Description = content.Description, Path = content.Path, OwnerId = content.User_ID, OwnerName = content.User.Name, CreationDate = content.Creation_Date
                            });
                        }

                        if (model.Contents.Count >= 4)
                        {
                            break;
                        }
                    }
                }

                //Retrieve Albums
                if (category == null || category.Equals("Album") || category.Equals("All"))
                {
                    var queryable = db.Albums.Where(a => a.Name.Contains(query) || a.Description.Contains(query));

                    foreach (Album album in queryable)
                    {
                        bool add = false;
                        if (album.Access == "Public")
                        {
                            add = true;
                        }
                        else if (User.Identity.IsAuthenticated)
                        {
                            string uid = User.Identity.GetUserId();

                            if (album.User_ID.Equals(uid))
                            {
                                add = true;
                            }
                            else
                            {
                                UserRelationship relationship = new UserRelationship();
                                if (album.Access == "Follower" && relationship.Following(album.User_ID, uid))
                                {
                                    add = true;
                                }
                                // if not blocked
                                // lol..... what about non logged in users :P
                            }
                        }

                        if (add)
                        {
                            model.Albums.Add(new ViewAlbumSearch {
                                Id = album.Album_ID, Title = album.Name, OwnerId = album.User_ID, OwnerName = album.User.Name, CreationDate = album.Creation_Date
                            });
                        }

                        if (model.Albums.Count >= 5)
                        {
                            break;
                        }
                    }
                }
            }

            ViewBag.Title = "" + query;
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Index(string ID)
        {
            List <StatusReport> reports = new List <StatusReport>();

            if (ID.IsNullOrWhiteSpace())
            {
                if (User.Identity.IsAuthenticated)
                {
                    ID = User.Identity.GetUserId();
                }
            }

            if (!ID.IsNullOrWhiteSpace())
            {
                using (PixurfDBContext db = new PixurfDBContext())
                {
                    User user = db.Users.Find(ID);

                    if (user != null)
                    {
                        UserRelationship relationship = new UserRelationship();
                        ViewUserModel    userModel    = new ViewUserModel
                        {
                            User_ID      = user.User_ID,
                            Name         = user.Name,
                            UserName     = user.UserName,
                            About_Me     = user.About_Me,
                            Admin        = user.Admin,
                            Country      = user.Country,
                            Email        = user.Email,
                            Joining_Date = user.Joining_Date,
                            PhoneNumber  = user.PhoneNumber,
                            Pro_Pic_ID   = user.Pro_Pic_ID,
                            Status       = user.Status,
                            Followers    = relationship.NoOfFollowers(user.User_ID)
                        };

                        if (User.Identity.IsAuthenticated)
                        {
                            if (User.Identity.GetUserId().Equals(ID))
                            {
                                userModel.MyProfile = true;
                            }
                        }


                        userModel.Albums          = this.GetViewableAlbums(user.User_ID);
                        userModel.PopularContents = this.GetViewableContents(user.User_ID);


                        return(View(userModel));
                    }
                }
            }



            reports.Add(new StatusReport
            {
                Title       = "Error",
                Description = "Profile not found",
                Status      = StatusReport.Danger
            });
            Session["Reports"] = reports;
            return(RedirectToAction("Index", "Home"));
        }