Exemple #1
0
        public List <string> GetHistory(int userOneID, int userTwoID, bool firstTime)
        {
            List <string> messageHistory = new List <string>();

            try
            {
                UsersDAO usersDAO = new UsersDAO();
                IEnumerable <MessagesList> messageList;
                messageList = (from record in socialNet.MessagesList
                               where (((record.SenderID == userOneID && record.RecepientID == userTwoID) ||
                                       (record.SenderID == userTwoID && record.RecepientID == userOneID))) || ((record.SenderID == userOneID) && (record.RecepientID == userTwoID))
                               select record);
                if (firstTime)
                {
                    foreach (MessagesList message in messageList)
                    {
                        message.Seen = 1;
                    }
                    socialNet.SaveChanges();
                }
                messageHistory = GetList(messageList, userOneID, userTwoID);
            }
            catch
            {
                string error = @"Unknown error occured :(";
                messageHistory.Add(error);
            }
            return(messageHistory);
        }
Exemple #2
0
        public void SetNewAvatar(int userID, int avatarID)
        {
            Users user = (from record in socialNet.Users
                          where record.ID == userID
                          select record).First();

            user.Avatar = avatarID;
            socialNet.SaveChanges();
        }
Exemple #3
0
        public void CreateAlbum(int creatorID, string title)
        {
            Albums album = new Albums
            {
                Creator = creatorID,
                Title   = title
            };

            socialNet.Albums.Add(album);
            socialNet.SaveChanges();
        }
Exemple #4
0
        public void AddRecord(int imageID, int albumID)
        {
            ImageAlbum imageAlbum = new ImageAlbum
            {
                IDAlbum = albumID,
                IDImage = imageID
            };

            socialNet.ImageAlbum.Add(imageAlbum);
            socialNet.SaveChanges();
        }
Exemple #5
0
        public bool AddRequest(int recepientID, int senderID)
        {
            bool requestAdded;

            try
            {
                RequestsList request = new RequestsList
                {
                    RecepientID = recepientID,
                    SenderID    = senderID
                };
                socialNet.RequestsList.Add(request);
                socialNet.SaveChanges();
                requestAdded = true;
            }
            catch
            {
                requestAdded = false;
            }
            return(requestAdded);
        }
Exemple #6
0
        public void AddNewAvatar(HttpPostedFileBase image, int userID)
        {
            byte[] data  = GetBytes(image);
            Albums album = (from record in socialNet.Albums
                            where record.Creator == userID && record.Title == "Avatars"
                            select record).First();
            int albumID = album.ID;

            albumsDAO.PlusOnePhoto(albumID);
            Images newImage = new Images()
            {
                Image = data
            };

            socialNet.Images.Add(newImage);
            socialNet.SaveChanges();
            int imageID = GetImageID(newImage);

            imageAlbumDAO.AddRecord(imageID, albumID);
            socialNet.SaveChanges();
            usersDAO.ChangeAvatar(userID, imageID);
        }
Exemple #7
0
        public bool AddUserInGroup(int friendID, int groupID, int userID)
        {
            bool done;

            try
            {
                UsersDAO             usersDAO    = new UsersDAO();
                Users                user        = usersDAO.GetByID(friendID);
                IEnumerable <Groups> groups      = groupsDAO.GetUserGroups(userID);
                List <int>           groupsID    = groups.Select(record => record.ID).ToList();
                List <int>           groupUserID = user.GroupUser.Select(record => record.IDGroup).ToList();
                List <int>           result      = groupsID.Intersect(groupUserID).ToList();
                if (result.Count() > 0)
                {
                    GroupUser groupUser = GetRecord(friendID, result.First());
                    groupUser.IDGroup = groupID;
                    socialNet.SaveChanges();
                }
                else
                {
                    GroupUser groupUser = new GroupUser
                    {
                        IDGroup = groupID,
                        IDUser  = friendID
                    };
                    socialNet.GroupUser.Add(groupUser);
                    socialNet.SaveChanges();
                }
                done = true;
            }
            catch
            {
                done = false;
            }
            return(done);
        }
Exemple #8
0
        public bool WriteRecord(string text, int authorID, int ownerID)
        {
            bool done;

            try
            {
                Records record = new Records
                {
                    Text   = text,
                    Author = authorID,
                    Owner  = ownerID
                };
                socialNet.Records.Add(record);
                socialNet.SaveChanges();
                done = true;
            }
            catch
            {
                done = false;
            }
            return(done);
        }
Exemple #9
0
        public void GetNewMessages()
        {
            SocialNetDataBaseEntities socialNet = new SocialNetDataBaseEntities();
            ChatController            chat      = new ChatController();

            while (true)
            {
                IEnumerable <MessagesList> messages = (from record in socialNet.MessagesList
                                                       where record.Seen == 0 && record.RecepientID == userID &&
                                                       record.SenderID == interlocutorID
                                                       select record);
                if (messages.Count() > 0)
                {
                    foreach (MessagesList message in messages)
                    {
                        message.Seen = 1;
                    }
                    socialNet.SaveChanges();
                    IsDone = true;
                }
            }
        }
Exemple #10
0
        public bool AddNewGroup(string groupTitle, int userID)
        {
            bool added;

            try
            {
                Groups group = new Groups
                {
                    Titile  = groupTitle,
                    Creator = userID
                };

                socialNet.Groups.Add(group);
                socialNet.SaveChanges();
                added = true;
            }
            catch
            {
                added = false;
            }
            return(added);
        }