示例#1
0
 public static List <User> Load()
 {
     using (GroceryGetterEntities dc = new GroceryGetterEntities())
     {
         List <User> users = new List <User>();
         dc.tblUsers.ToList().ForEach(u => users.Add(new User
         {
             Id          = u.Id,
             FirstName   = u.FirstName,
             LastName    = u.LastName,
             UserPass    = u.UserPass,
             Email       = u.Email,
             GroceryList = UserProductManager.LoadByUserId(u.Id)
         }));
         return(users);
     }
 }
示例#2
0
 public static bool Login(User user)
 {
     if (!string.IsNullOrEmpty(user.Email))
     {
         if (!string.IsNullOrEmpty(user.UserPass))
         {
             using (GroceryGetterEntities dc = new GroceryGetterEntities())
             {
                 tblUser tbluser = dc.tblUsers.FirstOrDefault(u => u.Email == user.Email);
                 if (tbluser != null)
                 {
                     //if(GetHash(tbluser.UserPass) == GetHash(user.UserPass)) //"gwhlGAT6y3ua+P/FOjOiLWocisI="
                     if (VerifyHash(tbluser.UserPass, user.UserPass))
                     {
                         user.FirstName   = tbluser.FirstName;
                         user.LastName    = tbluser.LastName;
                         user.Email       = tbluser.Email;
                         user.Id          = tbluser.Id;
                         user.GroceryList = UserProductManager.LoadByUserId(tbluser.Id);
                         return(true);
                     }
                     else
                     {
                         // return false;
                         throw new Exception("Login Failed!");   // Cannot log in with these credentials
                     }
                 }
                 else
                 {
                     //return false;
                     throw new Exception("Login Failed!");    // User not found
                 }
             }
         }
         else
         {
             throw new Exception("Password was not set!");
         }
     }
     else
     {
         throw new Exception("Email was not set!");  // This outputs to the view so I changed it to "Email"
     }
 }
示例#3
0
        public static User LoadByEmail(string email)
        {
            try
            {
                using (GroceryGetterEntities dc = new GroceryGetterEntities())
                {
                    tblUser tbluser = dc.tblUsers.FirstOrDefault(u => u.Email == email);
                    User    user    = new User();

                    if (tbluser != null)
                    {
                        user.Id        = tbluser.Id;
                        user.FirstName = tbluser.FirstName;
                        user.LastName  = tbluser.LastName;
                        user.Email     = tbluser.Email;
                        user.UserPass  = tbluser.UserPass;


                        tblUserProduct tbluserproduct = dc.tblUserProducts.FirstOrDefault(up => up.UserId == user.Id);

                        if (tbluserproduct != null)
                        {
                            user.GroceryList = UserProductManager.LoadByUserId(tbluser.Id);
                        }
                        return(user);
                    }
                    else
                    {
                        throw new Exception("Row was not found!!!!");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }