예제 #1
0
        public List <Profiles> getRandomProfiles()
        {
            using (var context = new UserDBEntities())
            {
                context.Database.Connection.Open();
                List <Profiles> list = context.Profiles.ToList();
                List <int>      ids  = new List <int>();
                foreach (var i in list)
                {
                    ids.Add(i.Id);
                }

                List <Profiles> filteredList = new List <Profiles>();
                Random          random       = new Random();
                List <int>      ranNumbers   = new List <int>();
                int             c            = 0;
                while (c < 5)
                {
                    int ran = ids[random.Next(ids.Count)];

                    if (!ranNumbers.Contains(ran))
                    {
                        ranNumbers.Add(ran);
                        filteredList.Add(getUserByID(ran));
                        c++;
                    }
                }


                return(filteredList);
            }
        }
예제 #2
0
 /// <summary>
 /// Hämtar alla användare
 /// </summary>
 public List <Profiles> fetchProfiles()
 {
     using (var context = new UserDBEntities())
     {
         context.Database.Connection.Open();
         return(context.Profiles.ToList());
     }
 }
예제 #3
0
 public bool getHide(int id)
 {
     using (var context = new UserDBEntities())
     {
         var hide = (from a in context.SECURITY
                     where (a.PID == id)
                     select a.VISIBILITY).SingleOrDefault();
         return(hide);
     }
 }
예제 #4
0
        public Profiles getUserByID(int id)
        {
            Profiles user;

            using (var context = new UserDBEntities())
            {
                user = context.Profiles.Find(id);
            }
            return(user);
        }
예제 #5
0
 public string getName(int id)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.Profiles
                     where (a.Id == id)
                     select a).SingleOrDefault();
         return(user.Firstname);
     }
 }
예제 #6
0
 public string getPAboutById(int id)
 {
     using (var context = new UserDBEntities())
     {
         var about = (from a in context.Profiles
                      where (a.Id == id)
                      select a.About).Single();
         return(about);
     }
 }
예제 #7
0
 /// <summary>
 ///  Hämtar en user med viss id
 /// </summary>
 public List <Profiles> findProfilesByName(string name)
 {
     using (var context = new UserDBEntities())
     {
         context.Database.Connection.Open();
         List <Profiles> profile = (from a in context.Profiles
                                    where (a.Lastname.Contains(name) || a.Firstname.Contains(name))
                                    select a).ToList();
         return(profile);
     }
 }
예제 #8
0
 public void UpdatePassword(int id, string newpass)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.SECURITY
                     where (a.PID == id)
                     select a).SingleOrDefault();
         user.PASSWORD = newpass;
         context.SaveChanges();
     }
 }
예제 #9
0
 public void setPAboutById(int id, string about)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.Profiles
                     where (a.Id == id)
                     select a).SingleOrDefault();
         user.About = about;
         context.SaveChanges();
     }
 }
예제 #10
0
 public void setPic(int id, string filename)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.Profiles
                     where (a.Id == id)
                     select a).SingleOrDefault();
         user.Pic = filename;
         context.SaveChanges();
     }
 }
예제 #11
0
 public bool comparePassword(int id, string oldpass)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.SECURITY
                     where (a.PID == id)
                     select a).SingleOrDefault();
         if (user.PASSWORD == oldpass)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #12
0
 /// <summary>
 /// Lägger till en användare i databasen
 /// </summary>
 public void insertUser(Profiles profile, SECURITY security)
 {
     try
     {
         using (var context = new UserDBEntities())
         {
             context.Database.Connection.Open();
             context.Profiles.Add(profile);
             context.SaveChanges();
             security.PID = profile.Id;
             context.SECURITY.Add(security);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
예제 #13
0
        public SECURITY loginUser(SECURITY user)
        {
            using (var context = new UserDBEntities())
            {
                context.Database.Connection.Open();
                SECURITY usr = null;
                try
                {
                    usr = context.SECURITY.Single(u => u.USERNAME == user.USERNAME && u.PASSWORD == user.PASSWORD);
                }
                catch
                {
                    usr = null;
                }

                return(usr);
            }
        }
예제 #14
0
 public void setHide(int id, bool choice)
 {
     using (var context = new UserDBEntities())
     {
         var hide = (from a in context.SECURITY
                     where (a.PID == id)
                     select a).SingleOrDefault();
         if (choice == true)
         {
             hide.VISIBILITY = true;
         }
         if (choice == false)
         {
             hide.VISIBILITY = false;
         }
         context.SaveChanges();
     }
 }