private AccountModel ValidateUser(string username, string password) { AccountModel user = null; using (SGFEntitiess sessionUser = new SGFEntitiess()) { var result = from i in sessionUser.SGF_T_USER where i.EMAIL == username && i.PASSWORD == password select new { i.USER_ID, i.NAME, i.EMAIL }; //result.ToList(); if (result.SingleOrDefault() != null) user = new AccountModel(result.First().USER_ID, result.First().NAME, result.First().EMAIL); } return user; }
private void CreateUser(string email, string password, string name, int nationality, int languagepref, out MembershipCreateStatus status) { using (SGFEntitiess sessionUser = new SGFEntitiess()) { //Valida se existe já User registado var result = from i in sessionUser.SGF_T_USER where i.EMAIL == email select i; //Já existe o email em questão if (result.SingleOrDefault() != null) { status = MembershipCreateStatus.DuplicateUserName; return; } string hashPassword = EncryptSHA256(password); SGF_T_USER s = SGF_T_USER.CreateSGF_T_USER(-1, name, hashPassword, email, DateTime.Now, nationality, languagepref); sessionUser.AddToSGF_T_USER(s); sessionUser.SaveChanges(); AccountModel userOnline = new AccountModel(s.USER_ID, s.NAME, s.EMAIL); Session["userOnline"] = userOnline; } status = MembershipCreateStatus.Success; return; }