Ejemplo n.º 1
0
        //Sign up - save the sign up date to the database
        public void AddUserAccount(UserModel user, AddressModel address)
        {
            using (ECommerceEntities db = new ECommerceEntities())
            {
                try
                {
                    PasswordManager PM = new PasswordManager();
                    t_Users US = new t_Users();
                    US.UserName = user.Username;
                    US.Password = PM.Encrypt(user.Password);
                    US.FirstName = user.FirstName;
                    US.LastName = user.LastName;
                    US.Email = user.Email;
                    US.Gender = user.Gender;
                    db.t_Users.Add(US);
                    //db.SaveChanges();
                    var result = db.Database.ExecuteSqlCommand("exec upSaveUser @UserName, @Password, @Email, @FirstName, @Surname, @Gender", new SqlParameter("UserName", US.UserName),
                        new SqlParameter("Password", US.Password), new SqlParameter("Email", US.Email), new SqlParameter("FirstName", US.FirstName), new SqlParameter("Surname", US.LastName),
                        new SqlParameter("Gender", US.Gender));

                    //AddressModel AD = new AddressModel();
                    t_UsersAddress TAD = new t_UsersAddress();
                    TAD.AddressNumber = address.AddressNumber;
                    TAD.AddressPostalCode = address.AddressPostalCode;
                    TAD.AddressRoadName = address.AddressRoadName;
                    TAD.AddressSuburb = address.AddressSuburb;

                    TAD.UID = US.UID;
                    TAD.AddressCity = address.AddressCity;
                    db.t_UsersAddress.Add(TAD);
                    //db.SaveChanges();

                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult Login(UserLogin ULV)
        {
            if (ModelState.IsValid)
            {
                UserManagerFK UM = new UserManagerFK();
                PasswordManager PM = new PasswordManager();

                string Password = UM.GetUserPassword(ULV.UserName);

                if (string.IsNullOrEmpty(Password))
                {
                    ModelState.AddModelError("", "Login Failed, Details Provided Are Incorrect.");
                }
                else
                {
                    if (/*PM.Encrypt*/(ULV.Password).Equals(Password))
                    {
                        FormsAuthentication.SetAuthCookie(ULV.UserName, false);
                        return RedirectToAction("Welcome", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Password Is Incorrect.");
                    }
                }
            }
            return View(ULV);
        }