Exemplo n.º 1
0
        /*Lägger till relation mellan angivna användare i Friendship-tabellen.
         * Det UserAccountID som var Sender på FriendRequest blir User i Friendship,
         * och det UserAccountID som var Reciever av FriendRequest blir Friend i Friendship
         */
        public void AcceptRequest(int user1, int user2)
        {
            using (var context = new OnlineDatingDBEntities())
            {
                //Kastar exception om Friendship redan finns i någon kombination av sender och reciever
                if (context.Friendship.Any(x => x.User == user1 && x.Friend == user2 || x.User == user2 && x.Friend == user1))
                {
                    throw new Exception("Already friends");
                }
                else
                {
                    var newFriendship = new Friendship
                    {
                        User      = user1,
                        Friend    = user2,
                        StartDate = DateTime.Now
                    };

                    var request = context.FriendRequest.First
                                  (
                        x => x.Sender == user1 && x.Reciever == user2
                                  );

                    context.Friendship.Add(newFriendship);
                    context.FriendRequest.Remove(request);
                    context.SaveChanges();;
                }
            }
        }
Exemplo n.º 2
0
 public void Add(string username, string password, string email)
 {
     using (var context = new OnlineDatingDBEntities())
     {
         var newUser = new UserAccount
         {
             Username     = username,
             Password     = password,
             Email        = email,
             Searchable   = true,
             Length       = "0",
             Weight       = "0",
             Build        = "Unspecified",
             Eyecolor     = "Unspecified",
             Haircolor    = "Unspecified",
             Origin       = "Unspecified",
             Civil_Status = "Unspecified",
             Occupation   = "Unspecified",
             Education    = "Unspecified",
             Branch       = "Unspecified",
         };
         context.UserAccount.Add(newUser);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
        //Sparar en sökväg till lokalt sparade bilder.
        public void SaveImagePath(string username, string imagePath)
        {
            using (var context = new OnlineDatingDBEntities())
            {
                var userToUpdate = context.UserAccount.First(x => x.Username == username);
                userToUpdate.ImagePath = imagePath;

                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void UpdateUser(UserAccount user)
        {
            using (var context = new OnlineDatingDBEntities())
            {
                var userToUpdate = context.UserAccount.First(x => x.UserAccountID == user.UserAccountID);
                userToUpdate = user;

                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void UpdateUser(string username, string newEmail, bool searchable, string city)
        {
            using (var context = new OnlineDatingDBEntities())
            {
                var userToUpdate = context.UserAccount.First(x => x.Username == username);

                userToUpdate.Email      = newEmail;
                userToUpdate.Searchable = searchable;
                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 //Tar bort två angedda användarIDn ur FriendRequest-tabellen
 public void DeleteRequest(int sender, int reciever)
 {
     using (var context = new OnlineDatingDBEntities())
     {
         var request = context.FriendRequest.First
                       (
             x => x.Sender == sender && x.Reciever == reciever ||
             x.Sender == reciever && x.Reciever == sender
                       );
         context.FriendRequest.Remove(request);
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 //Tar bort två angedda användarIDn ur Friendship-tabellen
 public void DeleteFriendship(int user, int friend)
 {
     using (var context = new OnlineDatingDBEntities())
     {
         var friendship = context.Friendship.First
                          (
             x => x.User == user && x.Friend == friend ||
             x.User == friend && x.Friend == user
                          );
         context.Friendship.Remove(friendship);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 //Lägger till avsändare, mottagare, text och tidpunkt i Message-tabellen
 public void AddMessage(int sender, int reciever, string text)
 {
     using (var context = new OnlineDatingDBEntities())
     {
         var messageToAdd = new Message
         {
             Sender   = sender,
             Reciever = reciever,
             Text     = text,
             Date     = DateTime.Now
         };
         context.Message.Add(messageToAdd);
         context.SaveChanges();
     }
 }
Exemplo n.º 9
0
 //Lägger till avsändare och mottagare mellan angivna användare i FriendRequest-tabellen
 public void AddRequest(int sender, int reciever)
 {
     using (var context = new OnlineDatingDBEntities())
     {
         //Kastar exception om Friendship eller FriendRequest redan finns i någon kombination av sender och reciever
         if (context.Friendship.Any(x => x.User == sender && x.Friend == reciever || x.User == reciever && x.Friend == sender ||
                                    context.FriendRequest.Any(y => y.Sender == sender && y.Reciever == reciever || y.Sender == reciever && y.Reciever == sender)))
         {
             throw new Exception("Already requested or friends");
         }
         else
         {
             var newRequest = new FriendRequest
             {
                 Sender   = sender,
                 Reciever = reciever
             };
             context.FriendRequest.Add(newRequest);
             context.SaveChanges();
         }
     }
 }