예제 #1
0
        //public Korisnik read(Korisnik entity) { }
        //public Korisnik update(Korisnik entity) { }
        //public void delete(Korisnik entity) { }


        public List <User> GetAllUsers()
        {
            try
            {
                using (UniContext context = new UniContext())
                {
                    List <User> users = context.Users.ToList <User>();

                    return(users);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #2
0
 public void CreateUser(User user)
 {
     try
     {
         using (var context = new UniContext())
         {
             if (user == null)
             {
                 throw new ArgumentNullException();
             }
             context.Users.Add(user);
             context.SaveChanges();
         }
     }
     catch (Exception e) {
         throw e;
     }
 }
예제 #3
0
 public void CreateFriendship(Friendship friendship)
 {
     try
     {
         if (friendship == null)
         {
             throw new ArgumentNullException();
         }
         using (var context = new UniContext())
         {
             context.Friendships.Add(friendship);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #4
0
 public void DeleteFriendship(Friendship friendship)
 {
     try
     {
         using (var context = new UniContext())
         {
             if (friendship == null)
             {
                 throw new ArgumentNullException();
             }
             Friendship tempFriendShip = (Friendship)context.Friendships.Where(f => f.Id == friendship.Id).First();
             context.Friendships.Remove(tempFriendShip);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #5
0
        public List <Friendship> GetFriendships(string username)
        {
            try
            {
                using (var context = new UniContext())
                {
                    if (username == null)
                    {
                        throw new ArgumentNullException();
                    }
                    List <Friendship> friendships = context.Friendships.Include("User").Include("Friend").Where(u => (u.User.UserName == username || u.Friend.UserName == username)).ToList <Friendship>();

                    return(friendships);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #6
0
        public Friendship GetFriendship(string username, string friendname)
        {
            try
            {
                using (var context = new UniContext())
                {
                    if (username == null || friendname == null)
                    {
                        throw new ArgumentNullException();
                    }
                    var friendship = context.Friendships.Include("User").Include("Friend").SingleOrDefault(u => (u.User.UserName == friendname && u.Friend.UserName == username) || u.User.UserName == username && u.Friend.UserName == friendname);

                    return(friendship);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #7
0
        public User GetUser(string username)
        {
            try
            {
                using (var context = new UniContext())
                {
                    if (username == null)
                    {
                        throw new ArgumentNullException();
                    }
                    var user = context.Users.Where(u => u.UserName == username).FirstOrDefault();

                    return(user);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #8
0
 public void UpdateFriendship(Friendship friendship)
 {
     try
     {
         using (var context = new UniContext())
         {
             if (friendship == null)
             {
                 throw new ArgumentNullException();
             }
             var result = context.Friendships.SingleOrDefault(u => u.Id == friendship.Id);
             if (result != null)
             {
                 result.Accepted = true;
                 context.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }