Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public User_Relation Blocked(String userId, String blockedId, bool getReference)
        {
            User_Relation relation =
                db.User_Relations.FirstOrDefault(
                    r => r.User_ID == userId && r.Related_User_ID == blockedId && r.Status == "Block");

            return(relation);
        }
Ejemplo n.º 3
0
        public User_Relation Following(String userId, String followerId, bool getReference)
        {
            User_Relation relation =
                db.User_Relations.FirstOrDefault(
                    r => r.User_ID == followerId && r.Related_User_ID == userId && r.Status == "Follow");

            return(relation);
        }
Ejemplo n.º 4
0
        public bool Blocked(String userId, String blockedId)
        {
            User_Relation relation =
                db.User_Relations.FirstOrDefault(
                    r => r.User_ID == userId && r.Related_User_ID == blockedId && r.Status == "Block");

            if (relation != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public bool Following(String userId, String followerId)
        {
            User_Relation relation =
                db.User_Relations.FirstOrDefault(
                    r => r.User_ID == followerId && r.Related_User_ID == userId && r.Status == "Follow");

            if (relation != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
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);
        }