Exemplo n.º 1
0
        public FavouriteStatus Set(int id)
        {
            FavouriteStatus status = new FavouriteStatus {
                Status = false
            };

            if (User.Identity.IsAuthenticated)
            {
                string uid = User.Identity.GetUserId();

                using (PixurfDBContext db = new PixurfDBContext())
                {
                    Favourite favourite = db.Favourites.FirstOrDefault(f => f.User_ID == uid && f.Content_ID == id);
                    Content   content   = db.Contents.Find(id);
                    if (content != null)
                    {
                        UserRelationship userRelationship = new UserRelationship();

                        if ((content.User_ID == uid) ||
                            (userRelationship.Following(content.User_ID, uid) && content.Access != "Private") ||
                            (!userRelationship.Blocked(content.User_ID, uid) && content.Access == "Public"))
                        {
                            if (favourite != null)
                            {
                                db.Favourites.Remove(favourite);
                                try
                                {
                                    db.SaveChanges();
                                    status.Status = false;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                    status.Status = true;
                                }
                            }
                            else
                            {
                                db.Favourites.Add(new Favourite
                                {
                                    Content       = content,
                                    User_ID       = uid,
                                    Creation_Date = DateTime.Now
                                });
                                try
                                {
                                    db.SaveChanges();
                                    status.Status = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                        }
                    }
                }
            }
            return(status);
        }
Exemplo n.º 2
0
        public FileResult Download(int id)
        {
            string uploadRoot = "~/UserUploads/";

            var strings = WebConfigurationManager.AppSettings.GetValues("UserUploadRoot");

            if (strings != null)
            {
                uploadRoot = strings.First();
            }
            var dir = Server.MapPath(uploadRoot);

            using (PixurfDBContext db = new PixurfDBContext())
            {
                Content content = db.Contents.Find(id);
                string  userId  = User.Identity.GetUserId();
                User    user    = db.Users.Find(userId);

                if (content != null && (content.User_ID == userId && content.Status == 1 || user != null && user.Admin))
                {
                    var    path     = Path.Combine(dir, content.User_ID + "\\" + content.Path); //validate the path for security or use other means to generate the path.
                    string fileName = content.Title + Path.GetExtension(content.Path);

                    byte[] fileBytes = System.IO.File.ReadAllBytes(path);
                    return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
                    //return File(path, "image/jpeg");
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            using (PixurfDBContext db = new PixurfDBContext())
            {
                List <Content> contents = db.Contents.Where(c => c.Access == "Public" && c.Status == 1).OrderByDescending(c => c.Creation_Date).Take(1).ToList();
                if (contents.Count > 0)
                {
                    int     contentId = contents[0].Content_ID;
                    Content content   = db.Contents.Find(contentId);

                    if (content != null)
                    {
                        ViewContentModel vcm = new ViewContentModel
                        {
                            Content_ID    = content.Content_ID,
                            Title         = content.Title,
                            Description   = content.Description,
                            Album         = content.Album,
                            Path          = content.Path,
                            User          = content.User,
                            Access        = content.Access,
                            Creation_Date = content.Creation_Date,
                            Status        = content.Status,
                            Type          = content.Type
                        };

                        return(View(vcm));
                    }
                }
            }


            return(View());
        }
Exemplo n.º 4
0
        private ViewContentModel GetContent(int id)
        {
            /////////////////////Handle deleted Content, private content
            using (PixurfDBContext db = new PixurfDBContext())
            {
                Content content = db.Contents.Find(id);

                if (content != null)
                {
                    ViewContentModel vcm = new ViewContentModel
                    {
                        Content_ID    = content.Content_ID,
                        Title         = content.Title,
                        Description   = content.Description,
                        Album         = content.Album,
                        Path          = content.Path,
                        User          = content.User,
                        Access        = content.Access,
                        Creation_Date = content.Creation_Date,
                        Status        = content.Status,
                        Type          = content.Type
                    };

                    if (content.Status != 0 || content.User.Admin)
                    {
                        //User gets it if not deleted
                        if (content.User_ID == User.Identity.GetUserId())
                        {
                            vcm.UserAuthenticated = true;
                            return(vcm);
                        }

                        if (content.User_ID != User.Identity.GetUserId())
                        {
                            if (content.Access == "Public")
                            {
                                return(vcm);
                            }

                            else if (content.Access == "Follower")
                            {
                                string loggInUserId   = User.Identity.GetUserId();
                                string contentOwnerId = content.User_ID;

                                User_Relation relation =
                                    db.User_Relations.FirstOrDefault(
                                        r => r.User_ID == loggInUserId && r.Related_User_ID == contentOwnerId);
                                if (relation != null)
                                {
                                    //Check for blocked user
                                    return(vcm);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        private List <Content> GetViewableContents(string ownerId)
        {
            List <Content> contents = new List <Content>();
            string         viewerId = "";

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

            using (PixurfDBContext db = new PixurfDBContext())
            {
                if (viewerId.IsNullOrWhiteSpace())
                {
                    //Only the public contents
                    contents = db.Contents.Where(a => a.User_ID == ownerId && a.Access == "Public" && a.Status == 1).Take(4).ToList();
                }
                else
                {
                    User viewer = db.Users.Find(viewerId);

                    if (viewer != null)
                    {
                        if (viewer.Admin)
                        {
                            contents = db.Contents.Where(a => a.User_ID == ownerId).Take(4).ToList();
                        }
                        else if (viewer.User_ID == ownerId)
                        {
                            contents = db.Contents.Where(a => a.User_ID == ownerId && a.Status == 1).Take(4).ToList();
                        }
                        else
                        {
                            //Handle followers
                            UserRelationship relationship = new UserRelationship();
                            if (relationship.Following(ownerId, viewerId))
                            {
                                contents = db.Contents
                                           .Where(a => a.User_ID == ownerId && a.Status == 1 &&
                                                  (a.Access == "Public" || a.Access == "Follower")).Take(4).ToList();
                            }
                            else
                            {
                                contents = db.Contents
                                           .Where(a => a.User_ID == ownerId && a.Status == 1 &&
                                                  a.Access == "Public").Take(4).ToList();
                            }
                        }
                    }
                }
            }


            return(contents);
        }
Exemplo n.º 6
0
        //[Route("api/{controller}/favourite/{action}/{id}")]
        public FavouriteStatus Get(int id)
        {
            FavouriteStatus status = new FavouriteStatus {
                Status = false
            };

            if (User.Identity.IsAuthenticated)
            {
                string uid = User.Identity.GetUserId();
                using (PixurfDBContext db = new PixurfDBContext())
                {
                    status.Status = db.Favourites.Any(f => f.User_ID == uid && f.Content_ID == id);
                }
            }
            return(status);
        }
Exemplo n.º 7
0
        // GET: Index
        // Get All Albums
        // So Far Complete
        public ActionResult Index()
        {
            List <StatusReport> reports = new List <StatusReport>();

            using (PixurfDBContext db = new PixurfDBContext())
            {
                string uid  = User.Identity.GetUserId();
                User   user = db.Users.Find(uid);

                if (user != null)
                {
                    ViewAlbumsModel allAlbumsModelModel = new ViewAlbumsModel();
                    List <Album>    albums = null;
                    if (user.Admin)
                    {
                        albums = db.Albums.Where(a => a.User_ID == uid).Include(a => a.Contents).Take(10).ToList();
                    }
                    else
                    {
                        albums = db.Albums.Where(a => a.User_ID == uid && a.Status == 1).Include(a => a.Contents)
                                 .Take(10).ToList();
                    }

                    foreach (Album album in albums)
                    {
                        allAlbumsModelModel.Albums.Add(album);
                    }

                    if (reports.Count > 0)
                    {
                        Session["Reports"] = reports;
                    }
                    return(View(allAlbumsModelModel));
                }
            }

            reports.Add(new StatusReport {
                Title       = "Error !",
                Description = "User id not found.",
                Status      = StatusReport.Danger
            });

            Session["Reports"] = reports;
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 8
0
        public ActionResult Stumble()
        {
            using (PixurfDBContext db = new PixurfDBContext())
            {
                if (User.Identity.IsAuthenticated)
                {
                    string           userId            = User.Identity.GetUserId();
                    UserRelationship relationship      = new UserRelationship();
                    List <string>    followedPeoplesId = relationship.GetFollowedPeoplesId(userId);

                    List <Content> contents = db.Contents.Where(c => //c.User_ID != userId &&
                                                                (c.Access == "Public" || (followedPeoplesId.Contains(c.User_ID) && (c.Access != "Public" || c.Access != "Follower"))))
                                              .OrderBy(c => Guid.NewGuid()).Take(1).ToList();

                    if (contents.Count > 0)
                    {
                        int contentId = contents[0].Content_ID;
                        return(RedirectToAction("View", "Content", new { id = contentId }));
                    }
                }
                else
                {
                    List <Content> contents = db.Contents.Where(c => c.Access == "Public").OrderBy(c => Guid.NewGuid()).Take(1).ToList();
                    if (contents.Count > 0)
                    {
                        int contentId = contents[0].Content_ID;
                        return(RedirectToAction("View", "Content", new { id = contentId }));
                    }
                }

                //Error Report
                StatusReport report = new StatusReport
                {
                    Title       = "Error",
                    Description = "Something went wrong. Please try again",
                    Status      = StatusReport.Warning
                };

                List <StatusReport> reports = new List <StatusReport>();
                reports.Add(report);

                Session["Reports"] = reports;
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 9
0
        public ActionResult Favourites()
        {
            List <StatusReport> reports = new List <StatusReport>();

            using (PixurfDBContext db = new PixurfDBContext())
            {
                string           userId     = User.Identity.GetUserId();
                List <Favourite> favourites = db.Favourites.Where(f => f.User_ID == userId).ToList();

                List <Content> favContents = new List <Content>();
                foreach (Favourite favourite in favourites)
                {
                    favContents.Add(db.Contents.Find(favourite.Content_ID));
                }


                return(View(favContents));
            }
        }
Exemplo n.º 10
0
        public ActionResult SlideShow(int id)
        {
            ViewAlbumModel albumModel;

            using (PixurfDBContext db = new PixurfDBContext())
            {
                Album album = db.Albums.Find(id);
                albumModel = new ViewAlbumModel
                {
                    Album_ID      = album.Album_ID,
                    Name          = album.Name,
                    Description   = album.Description,
                    User          = db.Users.Find(album.User_ID),
                    Access        = album.Access,
                    Status        = album.Status,
                    Creation_Date = album.Creation_Date,
                    Contents      = album.Contents.ToList()
                };
            }

            return(View(albumModel));
        }
Exemplo n.º 11
0
        public ActionResult Edit(ViewAlbumModel model)
        {
            List <StatusReport> reports = new List <StatusReport>();

            string userId = User.Identity.GetUserId();

            if (model != null && !model.Name.IsNullOrWhiteSpace() && !model.Access.IsNullOrWhiteSpace())
            {
                using (PixurfDBContext db = new PixurfDBContext())
                {
                    //Find the Album
                    Album album = db.Albums.Where(a => a.Album_ID == model.Album_ID)
                                  .OrderByDescending(a => a.Creation_Date).ToList().FirstOrDefault();

                    if (album == null)
                    {
                        reports.Add(new StatusReport
                        {
                            Title       = "Error",
                            Description = "Album not found",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;
                        return(RedirectToAction("Index"));
                    }
                    User user = db.Users.Find(userId);
                    if ((album.User_ID == userId && album.Status == 1) || (user != null && user.Admin))
                    {
                        if (album.Name == model.Name && album.Description == model.Description &&
                            album.Access == model.Access)
                        {
                            reports.Add(new StatusReport
                            {
                                Title       = "Success",
                                Description = "No change is made",
                                Status      = StatusReport.Success
                            });
                            Session["Reports"] = reports;
                            return(RedirectToAction("View", "Album", new { id = album.Album_ID }));
                        }
                        else
                        {
                            album.Name        = model.Name;
                            album.Description = model.Description;
                            album.Access      = model.Access;

                            try
                            {
                                db.SaveChanges();
                                reports.Add(new StatusReport
                                {
                                    Title       = "Success",
                                    Description = "Changes saved",
                                    Status      = StatusReport.Success
                                });
                                Session["Reports"] = reports;
                                return(RedirectToAction("View", "Album", new { id = album.Album_ID }));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                }
            }
            return(View(model));
        }
Exemplo n.º 12
0
        public ActionResult Delete(int id, string all)


        {
            bool deleteAll = false || (all != null && all.Equals("All"));

            List <StatusReport> reports = new List <StatusReport>();

            using (PixurfDBContext db = new PixurfDBContext())
            {
                Album  album  = db.Albums.Find(id);
                string userId = User.Identity.GetUserId();


                if (album == null)
                {
                    reports.Add(new StatusReport
                    {
                        Title       = "Failed",
                        Description = "Album not found",
                        Status      = StatusReport.Warning
                    });
                    Session["Reports"] = reports;
                    return(RedirectToAction("Index", "Album"));
                }


                // check if user own's the content && not already deleted
                if (album.Status == 1 && album.User_ID == userId)
                {
                    if (album.Name == "@System Generated Album@" && album.Contents.Count > 0)
                    {
                        reports.Add(new StatusReport
                        {
                            Title       = "Failed",
                            Description = "This Album can't be deleted as it's not empty.",
                            Status      = StatusReport.Warning
                        });
                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Album"));
                    }

                    album.Status = 0;

                    if (deleteAll)
                    {
                        foreach (Content content in album.Contents)
                        {
                            content.Status = 0;
                        }
                    }
                    else
                    {
                        //Find the Default Album
                        Album defaultAlbum = db.Albums.FirstOrDefault(a => a.Name == "@System Generated Album@" && a.User_ID == userId);

                        //Create the album if its null
                        if (defaultAlbum == null)
                        {
                            defaultAlbum = new Album
                            {
                                Name          = "@System Generated Album@",
                                Creation_Date = DateTime.Now,
                                User_ID       = userId,
                                Status        = 1,
                                Access        = "Private"
                            };
                        }
                        foreach (Content content in album.Contents)
                        {
                            content.Album = defaultAlbum;
                        }
                        db.Albums.Add(defaultAlbum);
                    }

                    try
                    {
                        db.SaveChanges();

                        reports.Add(new StatusReport
                        {
                            Title       = "Success",
                            Description = "Album " + album.Name + " successfully deleted.",
                            Status      = StatusReport.Success
                        });
                        Session["Reports"] = reports;
                    }
                    catch (Exception e)
                    {
                        reports.Add(new StatusReport
                        {
                            Title       = "Error",
                            Description = "Something went wrong",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;
                        Console.WriteLine(e);
                    }
                    return(RedirectToAction("Index", "Album"));
                }
                else
                {
                    var user = db.Users.Find(User.Identity.GetUserId());
                    if (user != null && user.Admin)
                    {
                        if (album.Name == "@System Generated Album@" && album.Contents.Count > 0)
                        {
                            reports.Add(new StatusReport
                            {
                                Title       = "Failed",
                                Description = "This Album can't be deleted as it's not empty.",
                                Status      = StatusReport.Warning
                            });
                            Session["Reports"] = reports;
                            return(RedirectToAction("Index", "Album"));
                        }

                        if (deleteAll)
                        {
                            List <Content> contents = album.Contents.ToList();
                            foreach (Content content in contents)
                            {
                                db.Contents.Remove(content);
                            }
                        }
                        else
                        {
                            //Find the Default Album
                            Album defaultAlbum =
                                db.Albums.FirstOrDefault(
                                    a => a.Name == "@System Generated Album@" && a.User_ID == album.User_ID);

                            //Create the album if its null
                            if (defaultAlbum == null)
                            {
                                defaultAlbum = new Album
                                {
                                    Name          = "@System Generated Album@",
                                    Creation_Date = DateTime.Now,
                                    User_ID       = album.User_ID,
                                    Status        = 1
                                };
                                db.Albums.Add(album);
                            }
                            foreach (Content content in album.Contents)
                            {
                                content.Album = defaultAlbum;
                            }
                        }

                        db.Albums.Remove(album);

                        try
                        {
                            db.SaveChanges();
                            reports.Add(new StatusReport
                            {
                                Title       = "Success",
                                Description = "Album " + album.Name + " has been deleted permanently.",
                                Status      = StatusReport.Success
                            });
                            Session["Reports"] = reports;
                            //Redirect to target users album index
                            return(RedirectToAction("Index", "Home"));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            reports.Add(new StatusReport
                            {
                                Title       = "Success",
                                Description = "Album " + album.Name + " Creation Successful.",
                                Status      = StatusReport.Success
                            });
                            Session["Reports"] = reports;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        reports.Add(new StatusReport
                        {
                            Title       = "Error",
                            Description = "Album not found",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;

                        return(RedirectToAction("Index", "Album"));
                    }
                }
            }
        }
Exemplo n.º 13
0
        // So Far Complete
        public ActionResult AddNew(ViewAlbumModel model)
        {
            List <StatusReport> reports = new List <StatusReport>();

            string userId = User.Identity.GetUserId();

            if (model != null && !model.Name.IsNullOrWhiteSpace() && !model.Access.IsNullOrWhiteSpace())
            {
                using (PixurfDBContext db = new PixurfDBContext())
                {
                    //Find the Album
                    Album album = db.Albums.Where(a => a.Name == model.Name && a.Status != 0 && a.User_ID == userId).OrderByDescending(a => a.Creation_Date).ToList().FirstOrDefault();

                    //Create the album if its null
                    if (album == null)
                    {
                        //Create an album
                        album = new Album
                        {
                            Name          = model.Name,
                            Creation_Date = DateTime.Now,
                            User_ID       = userId,
                            Access        = model.Access,
                            Status        = 1,
                            Description   = model.Description
                        };
                        db.Albums.Add(album);

                        try
                        {
                            db.SaveChanges();

                            reports.Add(new StatusReport
                            {
                                Title       = "Success",
                                Description = "Album " + album.Name + " Successfully Created.",
                                Status      = StatusReport.Success
                            });
                            Session["Reports"] = reports;
                        }
                        catch (Exception e)
                        {
                            reports.Add(new StatusReport
                            {
                                Title       = "Error",
                                Description = "Something went wrong",
                                Status      = StatusReport.Danger
                            });
                            Session["Reports"] = reports;
                            Console.WriteLine(e);
                        }
                    }
                    else
                    {
                        //Already Exists
                        reports.Add(new StatusReport
                        {
                            Title       = "Failed",
                            Description = "Album " + album.Name + " Already Exists.",
                            Status      = StatusReport.Warning
                        });
                        Session["Reports"] = reports;
                    }
                    return(RedirectToAction("View", new { id = album.Album_ID }));
                }
            }
            return(View(model));
        }
Exemplo n.º 14
0
        public RelationStatus Set(string id)
        {
            RelationStatus status = new RelationStatus {
                Type = RelationStatus.Follow
            };

            if (User.Identity.IsAuthenticated && !id.IsNullOrWhiteSpace())
            {
                string uid = User.Identity.GetUserId();

                using (PixurfDBContext db = new PixurfDBContext())
                {
                    User followingUser = db.Users.Find(id);
                    if (followingUser != null)
                    {
                        UserRelationship userRelationship = new UserRelationship();
                        bool             following        = userRelationship.Following(id, uid);
                        if (following)
                        {
                            db.User_Relations.Remove(db.User_Relations.FirstOrDefault(r => r.User_ID == uid && r.Related_User_ID == id && r.Status == "Follow"));

                            try
                            {
                                db.SaveChanges();
                                status.Status = false;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                status.Status = true;
                            }
                        }
                        else
                        {
                            bool isBlocked = userRelationship.Blocked(id, uid);
                            if (!isBlocked)
                            {
                                User_Relation relation = new User_Relation
                                {
                                    User_ID         = uid,
                                    Related_User_ID = id,
                                    Status          = "Follow"
                                };

                                db.User_Relations.Add(relation);

                                try
                                {
                                    db.SaveChanges();
                                    status.Status = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                    status.Status = false;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                status.Status = false;
            }
            return(status);
        }
Exemplo n.º 15
0
        public ActionResult Tag(string tag)
        {
            ViewSearchModel model = new ViewSearchModel
            {
                Query = "" + tag,
            };

            using (PixurfDBContext db = new PixurfDBContext())
            {
                IQueryable <Content> queryableContents = db.Contents.Where(c => c.Title.Contains("#" + tag) || c.Description.Contains("#" + tag));

                foreach (Content content in queryableContents)
                {
                    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

                IQueryable <Album> queryableAlbums = db.Albums.Where(a => a.Name.Contains("#" + tag) || a.Description.Contains("#" + tag));

                foreach (Album album in queryableAlbums)
                {
                    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 = "#" + tag;
            return(View(model));
        }
Exemplo n.º 16
0
        public ActionResult Edit(ViewContentModel model)
        {
            List <StatusReport> reports = new List <StatusReport>();

            string userId = User.Identity.GetUserId();

            if (model != null &&
                !model.Title.IsNullOrWhiteSpace() &&
                !model.Access.IsNullOrWhiteSpace() &&
                !model.Access.IsNullOrWhiteSpace())
            {
                using (PixurfDBContext db = new PixurfDBContext())
                {
                    //Find the Content
                    Content content = db.Contents.Find(model.Content_ID);

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

                    User user = db.Users.Find(userId);
                    if ((content.User_ID == userId && content.Status == 1) || (user != null && user.Admin))
                    {
                        if (content.Title == model.Title && content.Description == model.Description &&
                            content.Access == model.Access && content.Album.Name == model.AlbumName)
                        {
                            reports.Add(new StatusReport
                            {
                                Title       = "Success",
                                Description = "No change is made",
                                Status      = StatusReport.Info
                            });
                            Session["Reports"] = reports;
                            return(RedirectToAction("View", "Content", new { id = content.Content_ID }));
                        }
                        else
                        {
                            content.Title       = model.Title;
                            content.Description = model.Description;
                            content.Access      = model.Access;

                            Album album = null;
                            if (!model.AlbumName.IsNullOrWhiteSpace() && content.Album.Name != model.AlbumName)
                            {
                                //Find the Album
                                album = db.Albums.FirstOrDefault(a => a.Name == model.AlbumName && a.User_ID == userId);

                                //Create the album if its null
                                if (album == null)
                                {
                                    album = new Album {
                                        Name = model.AlbumName, Creation_Date = DateTime.Now, User_ID = userId, Access = model.Access, Status = 1
                                    };
                                    db.Albums.Add(album);
                                }
                                content.Album = album;
                            }

                            try
                            {
                                db.SaveChanges();
                                reports.Add(new StatusReport
                                {
                                    Title       = "Success",
                                    Description = "Changes saved",
                                    Status      = StatusReport.Success
                                });
                                Session["Reports"] = reports;
                                return(RedirectToAction("View", "Content", new { id = content.Content_ID }));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                }
            }

            reports.Add(new StatusReport
            {
                Title       = "Error",
                Description = "Fill the forms properly.",
                Status      = StatusReport.Danger
            });
            Session["Reports"] = reports;
            return(View(model));
        }
Exemplo n.º 17
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"));
        }
Exemplo n.º 18
0
        private StatusReport SaveContent(HttpPostedFileBase image, string access, string albumName)
        {
            string userId     = User.Identity.GetUserId();
            string dateTime   = DateTime.Now.Millisecond.ToString();
            string fileName   = userId + dateTime + Path.GetExtension(image.FileName);
            string uploadRoot = "~/UserUploads/";

            //Content & Thumbnail Save Loaction
            var strings = WebConfigurationManager.AppSettings.GetValues("UserUploadRoot");

            if (strings != null && strings.Length > 0)
            {
                uploadRoot = strings.First();
            }
            string contentPathWithRoot = uploadRoot + userId + "/";

            if (!Directory.Exists(Server.MapPath(contentPathWithRoot)))
            {
                Directory.CreateDirectory(Server.MapPath(contentPathWithRoot));
            }

            string thumbPathWithRoot = uploadRoot + userId + "/thumbs/";

            if (!Directory.Exists(Server.MapPath(thumbPathWithRoot)))
            {
                Directory.CreateDirectory(Server.MapPath(thumbPathWithRoot));
            }
            string thumbName     = "thumb_" + fileName;
            string thumbFullPath = Path.Combine(Server.MapPath(thumbPathWithRoot), thumbName);

            string fullFileName = Path.Combine(Server.MapPath(contentPathWithRoot), fileName);

            try
            {
                image.SaveAs(fullFileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new StatusReport {
                    Status = StatusReport.Danger, Title = "Save Failed", Description = image.FileName
                });
            }

            //update database
            using (PixurfDBContext db = new PixurfDBContext())
            {
                Content content = new Content
                {
                    Access        = access,
                    Title         = Path.GetFileNameWithoutExtension(image.FileName),
                    Path          = fileName,
                    Type          = image.ContentType,
                    User_ID       = userId,
                    Status        = 1,
                    Creation_Date = DateTime.Now
                };

                //update album or create and update album
                //Add to album
                string alName = albumName;
                Album  album;

                if (!alName.IsNullOrWhiteSpace())
                {
                    //Find the Album
                    album = db.Albums.FirstOrDefault(a => a.Name == alName && a.User_ID == userId);

                    //Create the album if its null
                    if (album == null)
                    {
                        album = new Album {
                            Name = alName, Creation_Date = DateTime.Now, User_ID = userId, Access = access, Status = 1
                        };
                        db.Albums.Add(album);
                    }
                }
                else
                {
                    album = new Album {
                        Name = "@System Generated Album@", Creation_Date = DateTime.Now, User_ID = userId, Status = 1
                    };
                    db.Albums.Add(album);
                }

                album.Contents.Add(content);


                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine(@"Entity of type ""{0}"" in state ""{1}"" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine(@"- Property: ""{0}"", Value: ""{1}"", Error: ""{2}""",
                                              ve.PropertyName,
                                              eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                              ve.ErrorMessage);
                        }
                    }
                    //throw;
                    return(new StatusReport
                    {
                        Status = StatusReport.Danger,
                        Title = "Save Failed",
                        Description = image.FileName
                    });
                }
            }

            // Save a Thumbnail of the Image
            ImageProcessor imageProcessor = new ImageProcessor();

            Image thumb = imageProcessor.CreateThumbnail(Image.FromStream(image.InputStream, true, true));

            thumb.Save(thumbFullPath, ImageFormat.Bmp);



            return(new StatusReport
            {
                Status = StatusReport.Success,
                Title = "Successfully Saved",
                Description = image.FileName
            });
        }
Exemplo n.º 19
0
        public ActionResult View(int id)
        {
            List <StatusReport> reports = new List <StatusReport>();

            using (PixurfDBContext db = new PixurfDBContext())
            {
                Content content = db.Contents.Find(id);

                if (content == null)
                {
                    reports.Add(new StatusReport
                    {
                        Title       = "None",
                        Description = "Content not found",
                        Status      = StatusReport.Warning
                    });
                    Session["Reports"] = reports;
                    return(RedirectToAction("Index", "Home"));
                }

                ViewContentModel vcm = new ViewContentModel
                {
                    Content_ID    = content.Content_ID,
                    Title         = content.Title,
                    Description   = content.Description,
                    Album         = content.Album,
                    Path          = content.Path,
                    User          = content.User,
                    Access        = content.Access,
                    Creation_Date = content.Creation_Date,
                    Status        = content.Status,
                    Type          = content.Type
                };

                if (content.Status == 1)
                {
                    if (content.User_ID == User.Identity.GetUserId())
                    {
                        if (reports.Count > 0)
                        {
                            Session["Reports"] = reports;
                        }

                        vcm.UserAuthenticated = true;
                        return(View(vcm));
                    }

                    UserRelationship relationship = new UserRelationship();
                    //Private
                    if (content.Access == "Private")
                    {
                        StatusReport report = new StatusReport
                        {
                            Title       = "Access Denied",
                            Description = "This content is not accessible",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                    //Follower
                    else if (content.Access == "Follower")
                    {
                        if (relationship.Following(content.User_ID, User.Identity.GetUserId()))
                        {
                            if (reports.Count > 0)
                            {
                                Session["Reports"] = reports;
                            }
                            return(View(vcm));
                        }
                        else
                        {
                            StatusReport report = new StatusReport
                            {
                                Title       = "Access Denied",
                                Description = "Only Followers can view this content",
                                Status      = StatusReport.Warning
                            };

                            reports.Add(report);

                            Session["Reports"] = reports;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    //Not Blocked
                    else
                    {
                        if (!relationship.Blocked(content.User_ID, User.Identity.GetUserId()))
                        {
                            if (reports.Count > 0)
                            {
                                Session["Reports"] = reports;
                            }
                            return(View(vcm));
                        }
                        StatusReport report = new StatusReport
                        {
                            Title       = "Error",
                            Description = "Content not found",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    User user = db.Users.Find(User.Identity.GetUserId());
                    if (user != null && user.Admin)
                    {
                        if (reports.Count > 0)
                        {
                            Session["Reports"] = reports;
                        }
                        return(View(vcm));
                    }
                    else
                    {
                        StatusReport report = new StatusReport
                        {
                            Title       = "Error",
                            Description = "Content not found",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
        }
Exemplo n.º 20
0
        public ActionResult View(int id)
        {
            List <StatusReport> reports = new List <StatusReport>();

            using (PixurfDBContext db = new PixurfDBContext())
            {
                Album album = db.Albums.Find(id);
                if (album == null)
                {
                    StatusReport report = new StatusReport
                    {
                        Title       = "Error",
                        Description = "Album not found",
                        Status      = StatusReport.Info
                    };

                    reports.Add(report);

                    Session["Reports"] = reports;
                    return(RedirectToAction("Index", "Home"));
                }

                ViewAlbumModel albumModel = new ViewAlbumModel
                {
                    Album_ID          = album.Album_ID,
                    Name              = album.Name,
                    Description       = album.Description,
                    User              = db.Users.Find(album.User_ID),
                    Access            = album.Access,
                    Status            = album.Status,
                    Creation_Date     = album.Creation_Date,
                    UserAuthenticated = false
                };

                if (album.Status == 1)
                {
                    if (album.User_ID == User.Identity.GetUserId())
                    {
                        if (reports.Count > 0)
                        {
                            Session["Reports"] = reports;
                        }
                        albumModel.Contents          = album.Contents.ToList();
                        albumModel.UserAuthenticated = true;
                        return(View(albumModel));
                    }

                    UserRelationship relationship = new UserRelationship();


                    //Private
                    if (album.Access == "Private")
                    {
                        StatusReport report = new StatusReport
                        {
                            Title       = "Access Denied",
                            Description = "This Album is not accessible",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                    //Follower
                    else if (album.Access == "Follower")
                    {
                        if (relationship.Following(album.User_ID, User.Identity.GetUserId()))
                        {
                            if (reports.Count > 0)
                            {
                                Session["Reports"] = reports;
                            }
                            var temp = album.Contents.Where(c => c.Access != "Private").ToList();
                            albumModel.Contents = temp;
                            return(View(albumModel));
                        }
                        else
                        {
                            StatusReport report = new StatusReport
                            {
                                Title       = "Access Denied",
                                Description = "Only Followers can view this Album",
                                Status      = StatusReport.Warning
                            };

                            reports.Add(report);

                            Session["Reports"] = reports;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    //Not Blocked
                    else
                    {
                        if (relationship.Following(album.User_ID, User.Identity.GetUserId()))
                        {
                            if (reports.Count > 0)
                            {
                                Session["Reports"] = reports;
                            }
                            var temp = album.Contents.Where(c => c.Access != "Private").ToList();
                            albumModel.Contents = temp;
                            return(View(albumModel));
                        }
                        else if (!relationship.Blocked(album.User_ID, User.Identity.GetUserId()))
                        {
                            if (reports.Count > 0)
                            {
                                Session["Reports"] = reports;
                            }
                            var temp = album.Contents.Where(c => c.Access == "Public").ToList();
                            albumModel.Contents = temp;
                            return(View(albumModel));
                        }


                        StatusReport report = new StatusReport
                        {
                            Title       = "Error",
                            Description = "Album not found",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    User user = db.Users.Find(User.Identity.GetUserId());
                    if (user != null && user.Admin)
                    {
                        if (reports.Count > 0)
                        {
                            Session["Reports"] = reports;
                        }
                        albumModel.UserAuthenticated = true;
                        return(View(albumModel));
                    }
                    else
                    {
                        StatusReport report = new StatusReport
                        {
                            Title       = "Error",
                            Description = "Album not found",
                            Status      = StatusReport.Warning
                        };

                        reports.Add(report);

                        Session["Reports"] = reports;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
0
 public UserRelationship()
 {
     db = new PixurfDBContext();
 }
Exemplo n.º 23
0
        /// Work Space ///
        ///
        public ActionResult Delete(int id)
        {
            List <StatusReport> reports = new List <StatusReport>();


            using (PixurfDBContext db = new PixurfDBContext())
            {
                Content content = db.Contents.Find(id);
                string  userId  = User.Identity.GetUserId();

                if (content == null)
                {
                    reports.Add(new StatusReport
                    {
                        Title       = "Failed",
                        Description = "Content not found",
                        Status      = StatusReport.Danger
                    });
                    Session["Reports"] = reports;
                    return(RedirectToAction("Index", "Content"));
                }
                // check if user own's the content and not already deleted

                if (content.Status == 1 && content.User_ID == userId)
                {
                    content.Status = 0;
                    try
                    {
                        db.SaveChanges();
                        reports.Add(new StatusReport
                        {
                            Title       = "Success",
                            Description = "Content succesfully deleted.",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;

                        return(RedirectToAction("View", "Album", new { id = content.Album_ID }));
                        //Redirect to album instead//
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        reports.Add(new StatusReport
                        {
                            Title       = "Error",
                            Description = "Something went wrong",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;
                        return(RedirectToAction("View", "Album", new { id = content.Album_ID }));
                    }
                }


                var user = db.Users.Find(userId);
                if (user != null && user.Admin)
                {
                    try
                    {
                        //Remove the file and it thumbnail from disk
                        string uploadRoot = "~/UserUploads/";

                        //Content & Thumbnail Save Loaction
                        var strings = WebConfigurationManager.AppSettings.GetValues("UserUploadRoot");
                        if (strings != null && strings.Length > 0)
                        {
                            uploadRoot = strings.First();
                        }

                        string contentPath = uploadRoot + content.User_ID + "/" + content.Path;
                        contentPath = Server.MapPath(contentPath);
                        if (System.IO.File.Exists(contentPath))
                        {
                            System.IO.File.Delete(contentPath);
                        }

                        string thumbPath = uploadRoot + content.User_ID + "/thumbs/thumb_" + content.Path;
                        thumbPath = Server.MapPath(thumbPath);
                        if (System.IO.File.Exists(thumbPath))
                        {
                            System.IO.File.Delete(thumbPath);
                        }

                        db.Contents.Remove(content);
                        db.SaveChanges();

                        reports.Add(new StatusReport
                        {
                            Title       = "Success",
                            Description = "Content permanently deleted.",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;

                        return(RedirectToAction("View", "Album", new { id = content.Album_ID }));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        reports.Add(new StatusReport
                        {
                            Title       = "Error",
                            Description = "Something went wrong",
                            Status      = StatusReport.Danger
                        });
                        Session["Reports"] = reports;
                        return(RedirectToAction("View", "Album", new { id = content.Album_ID }));
                    }
                }
            }
            return(RedirectToAction("Index", "Album"));
        }