Example #1
0
        public static Chat CreateChat(int UserOneID, int UserTwoID)
        {
            chat chat = new chat();
            using (var context = new HotSaleDBEntities())
            {

                chat.user1 = context.users.ToList().SingleOrDefault(x => x.ID == UserOneID);
                chat.user2 = context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID);
                context.chats.Add(chat);
                context.SaveChanges();
                context.users.ToList().SingleOrDefault(x => x.ID == UserOneID).chats.Add(chat);
                context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID).chats.Add(chat);
                context.SaveChanges();

            }
            Chat Chat = new Chat();
            Chat.ID = chat.ID;
            Chat.UserFirst = new User();
            Chat.UserFirst.ID = chat.user1.ID;
            Chat.UserFirst.Name = chat.user1.Name;
            Chat.UserFirst.Surname = chat.user1.Surname;
            Chat.UserFirst.Avatar = chat.user1.Avatar;
            Chat.UserSecond = new User();
            Chat.UserSecond.ID = chat.user2.ID;
            Chat.UserSecond.Name = chat.user2.Name;
            Chat.UserSecond.Surname = chat.user2.Surname;
            Chat.UserSecond.Avatar = chat.user2.Avatar;
            Chat.Messages = new List<Messages>();

            return Chat;
        }
Example #2
0
        public static Messages AddMessage(int ChatID, string Sender, string Message)
        {
            message mssg = new message();

            using (var context = new HotSaleDBEntities())
            {

                mssg.Message1 = Message;
                mssg.Sender = Sender;
                mssg.chat = context.chats.ToList().SingleOrDefault(x => x.ID == ChatID);
                mssg.Chat_ID = ChatID;
                context.messages.Add(mssg);
                context.SaveChanges();

                context.chats.ToList().SingleOrDefault(x => x.ID == ChatID).messages.Add(mssg);
                context.SaveChanges();

            }
            return new Messages() { ID = mssg.ID, Sender = Sender, Message = Message };
        }
Example #3
0
 public static IList<Chat> GetChats(List<int> ChatIDs)
 {
     IList<Chat> Chats = new List<Chat>();
     using (var context = new HotSaleDBEntities())
     {
         context.chats.ToList().ForEach(chat =>
     {
         ChatIDs.ForEach(id =>
         {
             if(chat.ID == id)
             {
                 Chat Chat = new Chat();
                 Chat.ID = id;
                 Chat.UserFirst = new User();
                 Chat.UserFirst.ID = chat.user1.ID;
                 Chat.UserFirst.Name = chat.user1.Name;
                 Chat.UserFirst.Surname = chat.user1.Surname;
                 Chat.UserFirst.Avatar = chat.user1.Avatar;
                 Chat.UserSecond = new User();
                 Chat.UserSecond.ID = chat.user2.ID;
                 Chat.UserSecond.Name = chat.user2.Name;
                 Chat.UserSecond.Surname = chat.user2.Surname;
                 Chat.UserSecond.Avatar = chat.user2.Avatar;
                 chat.messages.ToList().ForEach(mssg => { Messages Mssg = new Messages();
                                                 Mssg.ID = mssg.ID;
                                                 Mssg.Message = mssg.Message1;
                                                 Mssg.Sender = mssg.Sender;
                                                 Chat.Messages.Add(Mssg);
                                                 });
                 Chats.Add(Chat);
             }
         });
     });
     }
     return Chats;
 }
Example #4
0
        public static user Testing()
        {
            user user = new user();
            user.Email = "test";
            user.Password = "******";
            user.Name = "test";
            user.Surname = "test";
            user.watchlist = "";

            using (var context = new HotSaleDBEntities())
            {
                context.users.Add(user);
                context.SaveChanges();
            }
            user User;
            using (var context = new HotSaleDBEntities())
            {
                 User = context.users.ToList().SingleOrDefault(x => x.Email == user.Email);

            }

            return User;
        }
Example #5
0
        public static User ModifyUser(User User)
        {
            bool check = true;
            using (var context = new HotSaleDBEntities())
            {

                if (context.users.ToList().SingleOrDefault(x => x.Email == User.Email) != null)
                {
                    var user = context.users.ToList().SingleOrDefault(x => x.ID == User.ID);
                    user.Name = User.Name;
                    user.Surname = User.Surname;
                    user.Avatar = User.Avatar;
                    user.watchlist = User.watchlist;
                    context.SaveChanges();
                    check = false;
                }
            }
            if(check)
            { return new User(); }
            return User;
        }
Example #6
0
 public static User LoginUser(string Email, string Password)
 {
     User User = new User();
     using (var context = new HotSaleDBEntities())
     {
        var user = context.users.ToList().SingleOrDefault(x => x.Email == Email && x.Password == Password);
        if(user != null)
         {
             User.ID = user.ID;
             User.Email = user.Email;
             User.Password = user.Password;
             User.Name = user.Name;
             User.Surname = user.Surname;
             User.Avatar = user.Avatar;
             User.watchlist = user.watchlist;
             User.ItemWatchlist = new List<int>();
             user.items.ToList().ForEach(item => { User.ItemWatchlist.Add(item.ID); });
             User.ChatIds = new List<int>();
             user.chats.ToList().ForEach(chat => { User.ItemWatchlist.Add(chat.ID); });
         }
     }
     return User;
 }
Example #7
0
        public static User DeleteItemToWatchlist(int ID, string ItemInJson)
        {
            User User = new User();
            using (var context = new HotSaleDBEntities())
            {
                var user = context.users.ToList().SingleOrDefault(x => x.ID == ID);
                int index = user.watchlist.IndexOf(ItemInJson);
                int length = ItemInJson.Length;
                String startOfString = user.watchlist.Substring(0, index);
                String endOfString = user.watchlist.Substring(index + length);
                user.watchlist = startOfString + endOfString;
                context.SaveChanges();
                User.ID = user.ID;
                User.Email = user.Email;
                User.Password = user.Password;
                User.Name = user.Name;
                User.Surname = user.Surname;
                User.Avatar = user.Avatar;
                User.watchlist = user.watchlist;
                User.ItemWatchlist = new List<int>();
                user.items.ToList().ForEach(item => { User.ItemWatchlist.Add(item.ID); });
                User.ChatIds = new List<int>();
                user.chats.ToList().ForEach(chat => { User.ItemWatchlist.Add(chat.ID); });

            }
            return User;
        }
Example #8
0
 public static User CreateUser(User User)
 {
     user user = new user();
     user.Email = User.Email;
     user.Password = User.Password;
     user.Name = User.Name;
     user.Surname = User.Surname;
     user.watchlist = "";
     bool check = true;
     using (var context = new HotSaleDBEntities())
     {
         if (context.users.ToList().SingleOrDefault(x => x.Email == User.Email) == null)
         {
             context.users.Add(user);
             context.SaveChanges();
             check = false;
         }
     }
     if(check)
     {
         return new User();
     }
     return User;
 }
Example #9
0
 public static IList<User> AllUsers()
 {
     IList<User> Users = new List<User>();
     using (var context = new HotSaleDBEntities())
     {
         context.users.ToList().ForEach(user =>
         {
             User User = new User();
             User.ID = user.ID;
             User.Email = user.Email;
             User.Password = user.Password;
             User.Name = user.Name;
             User.Surname = user.Surname;
             User.Avatar = user.Avatar;
             User.watchlist = user.watchlist;
             User.ItemWatchlist = new List<int>();
             user.items.ToList().ForEach(item => { User.ItemWatchlist.Add(item.ID); });
             User.ChatIds = new List<int>();
             user.chats.ToList().ForEach(chat => { User.ItemWatchlist.Add(chat.ID); });
             Users.Add(User);
         });
     }
     return Users;
 }
Example #10
0
        public static User AddItemToWatchlist(int ID, string ItemInJson)
        {
            User User = new User();
            using (var context = new HotSaleDBEntities())
            {
                var user = context.users.ToList().SingleOrDefault(x => x.ID == ID);
                if (user.watchlist != "")
                { user.watchlist += ","; }
                user.watchlist += ItemInJson;
                context.SaveChanges();
                User.ID = user.ID;
                User.Email = user.Email;
                User.Password = user.Password;
                User.Name = user.Name;
                User.Surname = user.Surname;
                User.Avatar = user.Avatar;
                User.watchlist = user.watchlist;
                User.ItemWatchlist = new List<int>();
                user.items.ToList().ForEach(item => { User.ItemWatchlist.Add(item.ID); });
                User.ChatIds = new List<int>();
                user.chats.ToList().ForEach(chat => { User.ItemWatchlist.Add(chat.ID); });

            }
            return User;
        }
Example #11
0
 public static IList<Item> GetItems()
 {
     IList<Item> Items = new List<Item>();
     using (var context = new HotSaleDBEntities())
     {
         context.items.ToList().ForEach(item => {
                     Item Item = new Item();
                     Item.ID = item.ID;
                     Item.Class = item.Class;
                     Item.SubClass = item.SubClass;
                     Item.Price = item.Price;
                     Item.Photo = item.Photo;
                     Item.Params = item.Params;
                     Items.Add(Item);
         });
     }
     return Items;
 }
Example #12
0
 public static void DeleteItem(int UsrId,int ItmID)
 {
     using (var context = new HotSaleDBEntities())
     {
         context.items.Load();
         context.items.Remove(context.items.ToList().SingleOrDefault(x => x.ID == ItmID));
         context.SaveChanges();
         context.users.Load();
         context.users.ToList().SingleOrDefault(x => x.ID == UsrId).items.ToList().ForEach(item => {
             if(item.ID == ItmID)
             {
                 context.users.ToList().SingleOrDefault(x => x.ID == UsrId).items.ToList().Remove(context.users.ToList().SingleOrDefault(x => x.ID == UsrId).items.SingleOrDefault(x => x.ID == ItmID));
             }
         });
         context.SaveChanges();
     }
 }
Example #13
0
 public static Item AddItem(int UsrID ,Item Item)
 {
     item item = new item();
     item.Class = Item.Class;
     item.SubClass = Item.SubClass;
     item.Photo = Item.Photo;
     item.Price = Item.Price;
     item.Params = Item.Params;
     item.User_ID = UsrID;
     using (var context = new HotSaleDBEntities())
     {
         item.user = context.users.ToList().SingleOrDefault(x => x.ID == UsrID);
         context.items.Add(item);
         context.SaveChanges();
         context.users.ToList().SingleOrDefault(x => x.ID == UsrID).items.Add(item);
         context.SaveChanges();
         Item.ID = item.ID;
     }
     return Item;
 }