Esempio n. 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);
            }
        }
Esempio n. 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());
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 4
0
        public Profiles getUserByID(int id)
        {
            Profiles user;

            using (var context = new UserDBEntities())
            {
                user = context.Profiles.Find(id);
            }
            return(user);
        }
Esempio n. 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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)
     {
     }
 }
Esempio n. 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);
            }
        }
Esempio n. 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();
     }
 }