Exemple #1
0
 public string UpdateUser(BASE_USER user)
 {
     using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext())
     {
         try
         {
             string hashedPass = HashPassword.HashPass(user.Pass);
             var    query      = (from res in db.USERs where res.UserId.Equals(user.ID) select res);
             if (query.Count() != 0)
             {
                 USER toinsert = query.Single();
                 toinsert.Name     = user.Name;
                 toinsert.Surname  = user.Surname;
                 toinsert.Email    = user.Email;
                 toinsert.Password = hashedPass;
                 db.SubmitChanges();
                 return("success");
             }
             else
             {
                 return("failed: No Such User exist");
             }
         }
         catch (Exception)
         {
             return("failed");
         }
     };
 }
        public int registerUser(BASE_USER user)
        {
            try
            {
                string hashedPass = HashPassword.HashPass(user.Pass);
                using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext())
                {
                    int isAvail = (from eh in db.USERs where eh.Email.Equals(user.Email) select eh).Count();
                    if (isAvail == 0)
                    {
                        USER _user = new USER();
                        _user.Name      = user.Name;
                        _user.Level     = user.Level;
                        _user.Surname   = user.Surname;
                        _user.Email     = user.Email;
                        _user.Password  = hashedPass;
                        _user.UserImage = user.imgLocation;
                        db.USERs.InsertOnSubmit(_user);
                        db.SubmitChanges();
                    }
                };

                using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext())
                {
                    var  queryID = (from eh in db.USERs where eh.Email.Equals(user.Email) select eh);
                    USER res     = queryID.Single();
                    int  ID      = res.UserId;
                    return(ID);
                };
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemple #3
0
        public BASE_USER Login(string email, string password)
        {
            string hashedPass = HashPassword.HashPass(password);

            using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext())
            {
                try
                {
                    return(db.USERs.Where(pe => pe.Email == email && pe.Password == hashedPass).Select(pe => new BASE_USER
                    {
                        ID = pe.UserId,
                        Name = pe.Name,
                        Email = pe.Email,
                        Surname = pe.Surname,
                        Pass = pe.Password,
                        Level = pe.Level
                    }).First());
                }
                catch
                {
                    return(null);
                }
            };
        }