Esempio n. 1
0
        public bool AddToMyInterests(int userId, int interestId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.UserInterests.FirstOrDefault(i => i.InterestId == interestId && i.UserId == userId);

                if (item != null)
                {
                    db.UserInterests.Remove(item);

                    db.SaveChanges();

                    return(false);
                }


                db.UserInterests.Add(new UserInterest
                {
                    UserId     = userId,
                    InterestId = interestId,
                    AddDate    = DateTime.Now
                });

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 2
0
        public List <InterestEntity> GetInterestObjectsByName(List <string> interests, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var interestObjects = new List <InterestEntity>();

                foreach (var inter in interests)
                {
                    var item = db.Interests.FirstOrDefault(i => i.Name == inter);

                    if (item != null)
                    {
                        interestObjects.Add(new InterestEntity {
                            Id     = item.Id,
                            Name   = item.Name,
                            UserId = item.UserId
                        });
                    }
                    else
                    {
                        var newInt = new Interest
                        {
                            Name    = inter,
                            UserId  = userId,
                            AddDate = DateTime.Now
                        };

                        db.Interests.Add(newInt);

                        db.SaveChanges();

                        db.UserInterests.Add(new UserInterest {
                            UserId     = userId,
                            InterestId = newInt.Id,
                            AddDate    = DateTime.Now
                        });

                        db.SaveChanges();

                        interestObjects.Add(new InterestEntity
                        {
                            Id     = newInt.Id,
                            Name   = newInt.Name,
                            UserId = newInt.UserId
                        });
                    }
                }

                return(interestObjects);
            }
        }
Esempio n. 3
0
        public void UpdateUser(UserEntity user)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.Users.FirstOrDefault(i => i.Id == user.Id);

                if (us == null)
                {
                    return;
                }

                us.FirstName = user.FirstName;
                us.LastName  = user.LastName;
                us.UserName  = "";

                us.Email = user.Email;

                us.DateOfBirth = user.DateOfBirth;
                us.Gender      = user.Gender;

                if (us.Password != "")
                {
                    us.Password = user.Password;
                }

                db.SaveChanges();
            }
        }
Esempio n. 4
0
        private void NewPostsCountByNearby(int id, int userId, out int newPostsCount, out int allPostCount)
        {
            using (var db = new groubel_dbEntities1())
            {
                var userIp = db.Users.FirstOrDefault(i => i.Id == userId).LastLoginIp;

                var ip = userIp;

                if (ip.Split('.').Count() > 2)
                {
                    var t = ip.Split('.');

                    ip = t[0] + "." + t[1] + "." + t[2];
                }

                allPostCount = db.Posts.Count(i => i.Ip.StartsWith(ip));

                var tp = (int)NotificationTypeEnum.PostAddedOnInterest;

                var up = db.Notifications.Where(i => i.Type == tp && i.ReciverUserId == userId && i.SeenStatus == false && i.AliasId == id).ToList();

                newPostsCount = up.Count();

                up.ForEach(a => { a.SeenStatus = true; a.ApproovedStatus = true; });

                db.SaveChanges();
            }
        }
Esempio n. 5
0
        public Tuple <Dictionary <string, int>, int> RatePost(PostRatesEntity rate)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.Rates.FirstOrDefault(i => i.PostId == rate.PostId && i.UserId == rate.UserId && i.Rate1 == rate.Rate1);

                if (item != null)
                {
                    db.Rates.Remove(item);
                }
                else
                {
                    item = db.Rates.FirstOrDefault(i => i.PostId == rate.PostId && i.UserId == rate.UserId);

                    if (item != null)
                    {
                        db.Rates.Remove(item);
                    }

                    db.Rates.Add(new Rate
                    {
                        UserId = rate.UserId,
                        PostId = rate.PostId,
                        Rate1  = rate.Rate1
                    });
                }

                db.SaveChanges();

                _notificationService.AddNotification(rate.UserId, 0, NotificationTypeEnum.LikedYourPost, rate.PostId, "", null);

                return(GetRate(rate.PostId, rate.UserId));
            }
        }
Esempio n. 6
0
        public bool MuteUser(int adminUserId, int chatId, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var isAdmin = db.Chats.Any(i => i.UserId == adminUserId && i.Id == chatId);

                if (!isAdmin)
                {
                    return(false);
                }

                var u = db.ChatMembers.FirstOrDefault(i => i.RoomId == chatId && i.UserId == userId);

                if (u == null)
                {
                    return(false);
                }

                u.Status = 3;

                db.SaveChanges();

                _notificationService.AddNotification(adminUserId, userId, NotificationTypeEnum.ChangedYouStatusInRoom, u.RoomId, "", null);

                return(true);
            }
        }
Esempio n. 7
0
        public PostCommentEntity AddComment(PostCommentEntity comment, HttpPostedFileBase file)
        {
            var upload = new IOHandler("~/Uploads/PostAttachements/");

            var name = upload.Save(file);

            using (var db = new groubel_dbEntities1())
            {
                var newComment = new PostComment
                {
                    Text        = comment.Text,
                    UserId      = comment.UserId,
                    Date        = DateTime.Now,
                    PostId      = comment.PostId,
                    Attachement = name
                };

                db.PostComments.Add(newComment);
                db.SaveChanges();

                comment.Id          = newComment.Id;
                comment.Attachement = name;
                comment.User        = _userService.GetUserById(comment.UserId, comment.UserId);

                _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.CmmentedOnYourPost, comment.PostId, "", null);

                return(comment);
            }
        }
Esempio n. 8
0
        public string AddImage(HttpPostedFileBase file, int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.UserImages.FirstOrDefault(i => i.UserId == id);

                var upload = new IOHandler("~/Uploads/ProfileImages/");

                var name = upload.Save(file);

                if (us == null)
                {
                    db.UserImages.Add(new UserImage {
                        UserId = id, Image = name, Sort = 0, IsMain = false, AddDate = DateTime.Now
                    });
                }
                else
                {
                    us.Image = name;
                }

                db.SaveChanges();

                return(name);
            }
        }
Esempio n. 9
0
        public bool AddUser(int chatId, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var userCount = db.ChatMembers.Count(i => i.RoomId == chatId);

                var room = db.Chats.FirstOrDefault(i => i.Id == chatId);

                if (room == null)
                {
                    return(false);
                }

                var isMember = db.ChatMembers.Any(i => i.UserId == userId && i.RoomId == chatId);

                if (isMember)
                {
                    return(false);
                }

                if (userCount >= room.MaxUsers)
                {
                    return(false);
                }

                var notification = db.Notifications.FirstOrDefault(i => i.AliasId == chatId && i.SenderUserId == userId);

                if (notification != null)
                {
                    notification.ApproovedStatus = true;
                    db.SaveChanges();
                }

                db.ChatMembers.Add(new ChatMember {
                    RoomId   = chatId,
                    SenderId = userId,
                    UserId   = userId,
                    Date     = DateTime.Now,
                    Agree    = true,
                    Avatar   = ""
                });

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 10
0
        public bool Register(UserEntity user)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.Users.FirstOrDefault(i => i.Email == user.Email);

                if (us != null)
                {
                    return(false);
                }

                var item = new User
                {
                    FirstName     = user.FirstName,
                    LastName      = user.LastName,
                    UserName      = user.UserName,
                    Email         = user.Email,
                    LastLoginDate = user.LastLoginDate,
                    LastLoginIp   = user.LastLoginIp,
                    DateOfBirth   = user.DateOfBirth,
                    RegisterDate  = user.RegiterDate,
                    Gender        = user.Gender,
                    Password      = user.Password,
                };

                db.Users.Add(item);

                db.SaveChanges();

                db.UserImages.Add(new UserImage {
                    UserId  = item.Id,
                    Image   = "http://groobl.com/uploads/profile.jpg",
                    IsMain  = true,
                    AddDate = DateTime.Now,
                    Sort    = 1
                });

                db.SaveChanges();

                _interestsService.AddInterestsToUser(item.Id, user.Interests.Select(i => i.Id).ToList());

                return(true);
            }
        }
Esempio n. 11
0
        public void SetApproved(int firstuserId, int secondUserId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var it = db.Notifications.FirstOrDefault(i => i.SenderUserId == firstuserId && i.ReciverUserId == secondUserId && i.Type == 11);

                if (it != null)
                {
                    it.ApproovedStatus = true;
                    db.SaveChanges();
                }

                it = db.Notifications.FirstOrDefault(i => i.SenderUserId == secondUserId && i.ReciverUserId == firstuserId && i.Type == 11);

                if (it != null)
                {
                    it.ApproovedStatus = true;
                    db.SaveChanges();
                }
            }
        }
Esempio n. 12
0
 public void ReportPost(int postId, int userId)
 {
     using (var db = new groubel_dbEntities1())
     {
         db.Reportings.Add(new Reporting
         {
             PostId = postId,
             UserId = userId,
         });
         db.SaveChanges();
     }
 }
Esempio n. 13
0
        public void HidePost(int postId, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                db.PostHides.Add(new PostHide
                {
                    PostId = postId,
                    UserId = userId
                });

                db.SaveChanges();
            }
        }
Esempio n. 14
0
        public void SubmitFriendship(int firstuserId, int secondUserId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item  = db.Friendships.FirstOrDefault(i => i.UserId == firstuserId && i.FriendId == secondUserId);
                var item2 = db.Friendships.FirstOrDefault(i => i.UserId == secondUserId && i.FriendId == firstuserId);

                item.Status  = true;
                item2.Status = true;

                db.SaveChanges();
            }
        }
Esempio n. 15
0
        public void SetApproved(int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var it = db.Notifications.FirstOrDefault(i => i.Id == id);

                if (it != null)
                {
                    it.ApproovedStatus = true;
                    db.SaveChanges();
                }
            }
        }
Esempio n. 16
0
        public bool AddFriend(int firstuserId, int secondUserId)
        {
            using (var db = new groubel_dbEntities1())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var item = db.Friendships.FirstOrDefault(i => i.UserId == firstuserId && i.FriendId == secondUserId);

                        if (item != null)
                        {
                            return(false);
                        }

                        db.Friendships.Add(new Friendship
                        {
                            UserId   = firstuserId,
                            FriendId = secondUserId,
                            Date     = DateTime.Now,
                            Status   = true
                        });

                        db.Friendships.Add(new Friendship
                        {
                            UserId   = secondUserId,
                            FriendId = firstuserId,
                            Date     = DateTime.Now,
                            Status   = true
                        });

                        db.SaveChanges();

                        _notificationService.SetApproved(firstuserId, secondUserId);

                        _notificationService.AddNotification(firstuserId, secondUserId, NotificationTypeEnum.AddEdYouAsFriend, 0, "", null);

                        transaction.Commit();

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        return(false);
                    }
                }
            }
        }
Esempio n. 17
0
        public bool RemoveFriend(int firstuserId, int secondUserId)
        {
            using (var db = new groubel_dbEntities1())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var item  = db.Friendships.FirstOrDefault(i => i.UserId == firstuserId && i.FriendId == secondUserId);
                        var item2 = db.Friendships.FirstOrDefault(i => i.UserId == secondUserId && i.FriendId == firstuserId);

                        if (item == null)
                        {
                            return(false);
                        }

                        db.Friendships.Remove(item);

                        db.Friendships.Remove(item2);

                        var st = new List <int> {
                            9, 11
                        };

                        var not = db.Notifications
                                  .Where(i => i.SenderUserId == firstuserId && i.ReciverUserId == secondUserId && st.Contains(i.Type));
                        var not2 = db.Notifications
                                   .Where(i => i.SenderUserId == secondUserId && i.ReciverUserId == firstuserId && st.Contains(i.Type));


                        db.Notifications.RemoveRange(not);

                        db.Notifications.RemoveRange(not2);

                        db.SaveChanges();

                        transaction.Commit();

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        return(false);
                    }
                }
            }
        }
Esempio n. 18
0
        public void Ping(int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.Users.FirstOrDefault(i => i.Id == id);

                if (us == null)
                {
                    return;
                }

                us.LastLoginDate = DateTime.Now;

                db.SaveChanges();
            }
        }
Esempio n. 19
0
        public void ShowPost(int postId, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.PostHides.FirstOrDefault(i => i.PostId == postId && i.UserId == userId);

                if (item == null)
                {
                    return;
                }

                db.PostHides.Remove(item);

                db.SaveChanges();
            }
        }
Esempio n. 20
0
        //Chats

        public void CloseChat(int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.Chats.FirstOrDefault(i => i.Id == id);

                if (item == null)
                {
                    return;
                }

                item.IsArchive = true;

                db.SaveChanges();
            }
        }
Esempio n. 21
0
        public void DeleteComment(int id, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.PostComments.FirstOrDefault(i => i.Id == id && i.UserId == userId);

                if (item == null)
                {
                    return;
                }

                db.PostComments.Remove(item);

                db.SaveChanges();
            }
        }
Esempio n. 22
0
        private void NewPostsCountByAnonimus(int id, int userId, out int newPostsCount, out int allPostCount)
        {
            using (var db = new groubel_dbEntities1())
            {
                allPostCount = db.Posts.Count(i => i.Anonoimus);

                var tp = (int)NotificationTypeEnum.PostAddedOnInterest;

                var up = db.Notifications.Where(i => i.Type == tp && i.ReciverUserId == userId && i.SeenStatus == false && i.AliasId == id).ToList();

                newPostsCount = up.Count();

                up.ForEach(a => { a.SeenStatus = true; a.ApproovedStatus = true; });

                db.SaveChanges();
            }
        }
Esempio n. 23
0
        public ChatCommentEntity AddComment(ChatCommentEntity comment, HttpPostedFileBase file)
        {
            using (var db = new groubel_dbEntities1())
            {
                var upload = new IOHandler("~/Uploads/RoomFiles/");

                var name = upload.Save(file);

                var newComm = new ChatComment
                {
                    Attachement = name,
                    Date        = DateTime.Now,
                    RoomId      = comment.RoomId,
                    Text        = comment.Text,
                    UserId      = comment.UserId,
                    Image       = name,
                };

                db.ChatComments.Add(newComm);

                var rm = db.Chats.FirstOrDefault(i => i.Id == comment.RoomId && i.IsRoom == false);
                if (rm != null)
                {
                    rm.IsArchive = false;
                }

                db.SaveChanges();

                comment.Id          = newComm.Id;
                comment.Attachement = name;
                comment.Image       = name;
                comment.Date        = DateTime.Now;
                comment.User        = _userService.GetUserById(comment.UserId, comment.UserId);

                if (db.Chats.FirstOrDefault(i => i.Id == comment.RoomId).IsRoom)
                {
                    _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.CommentedInRoom, comment.RoomId, "", null);
                }
                else
                {
                    _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.SendMessageInChat, comment.RoomId, "", null);
                }

                return(comment);
            }
        }
Esempio n. 24
0
        public bool DeleteUser(int chatId, int userId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var u = db.ChatMembers.FirstOrDefault(i => i.RoomId == chatId && i.UserId == userId);

                if (u == null)
                {
                    return(false);
                }

                db.ChatMembers.Remove(u);

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 25
0
        private void SetSeen(List <Notification> items)
        {
            using (var db = new groubel_dbEntities1())
            {
                foreach (var it in items)
                {
                    var notItem = db.Notifications.FirstOrDefault(i => i.Id == it.Id);

                    if (notItem != null)
                    {
                        notItem.SeenStatus      = true;
                        notItem.ApproovedStatus = true;
                    }
                }

                db.SaveChanges();
            }
        }
Esempio n. 26
0
        public bool DeleteComment(int userId, int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.ChatComments.FirstOrDefault(i => i.UserId == userId && i.Id == id);

                if (item == null)
                {
                    return(false);
                }

                db.ChatComments.Remove(item);

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 27
0
        public bool RemoveFromMyInterests(int userId, int interestId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var item = db.UserInterests.FirstOrDefault(i => i.InterestId == interestId && i.UserId == userId);

                if (item == null)
                {
                    return(false);
                }

                db.UserInterests.Remove(item);

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 28
0
        public void RequestAddToRoom(int userId, int adminId, int roomId)
        {
            using (var db = new groubel_dbEntities1())
            {
                var type = (int)NotificationTypeEnum.RequestedAddToRoom;
                db.Notifications.Add(new Notification
                {
                    SenderUserId    = userId,
                    ReciverUserId   = adminId,
                    Date            = DateTime.Now,
                    AliasId         = roomId,
                    ApproovedStatus = false,
                    SeenStatus      = false,
                    Type            = type
                });

                db.SaveChanges();
            }
        }
Esempio n. 29
0
        public bool UpdatePassword(string email, string pass)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.Users.FirstOrDefault(i => i.Email == email);

                if (us == null)
                {
                    return(false);
                }

                us.Password = pass;
                us.TempGuId = null;

                db.SaveChanges();

                return(true);
            }
        }
Esempio n. 30
0
        public bool SignIn(UserEntity user)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.Users.FirstOrDefault(i => i.Email == user.Email && i.Password == user.Password);

                if (us == null)
                {
                    return(false);
                }

                us.LastLoginDate = DateTime.Now;
                us.LastLoginIp   = user.LastLoginIp;

                db.SaveChanges();

                return(true);
            }
        }