Ejemplo 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);
        }
Ejemplo n.º 2
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"));
                    }
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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"));
                    }
                }
            }
        }