public ActionResult CreateUser(RegistrationModel rm) { if (rm.Password.Length < 6) { TempData["Message"] = "Password needs to be longer"; return(RedirectToAction("CreateUser")); } else { Account checkAccount = new BAAccount().GetAccountByUsername(rm.UserName); User checkEmail = new BAUser().GetUserByEmail(rm.Email); if (checkAccount == null && checkEmail == null) { Account acc = new Account(); acc.ID = Guid.NewGuid(); acc.Username = rm.UserName; acc.Password = rm.Password; new BAAccount().AddAccount(acc); Account a = new BAAccount().GetAccountByUsername(rm.UserName); //USer rm.user.ID = Guid.NewGuid(); rm.user.Name = rm.Name; rm.user.Surname = rm.Surname; rm.user.Email = rm.Email; rm.user.HouseNumber = rm.HouseNumber; rm.user.StreetName = rm.StreetName; rm.user.UserTypeID = rm.user.UserTypeID; rm.user.AccountID = a.ID; new BAUser().AddUser(rm.user); } else { if (checkAccount != null) { TempData["Message"] = "Username already exists"; } else if (checkEmail != null) { TempData["Email"] = "Email already exists"; } } } return(RedirectToAction("CreateUser")); //} //catch (Exception ex) //{ // TempData["CatchError"] = "An error was encountered. Please try again later"; // return RedirectToAction("RegisterUser"); //} }
public ActionResult Login(LoggingInModel model) { BAAccount baAccount = new BAAccount(); if (baAccount.GetAccountByUsernameAndPassword(model.UserName, model.Password) != null) { Account check = new BAAccount().GetAccountByUsername(model.UserName); if (check.Password.Equals(model.Password) && check.Username.Equals(model.UserName)) { FormsAuthentication.RedirectFromLoginPage(model.UserName, true); Session["username"] = model.UserName; Session["accountid"] = check.ID; Session["userID"] = new BAUser().GetUserByAccount(check.ID).ID; return(RedirectToAction("Index", "Home")); } else { ViewBag.Error = "Invalid Login credentials"; return(View()); } } else { ViewBag.Error = "Invalid Login credentials"; return(View()); } //if (new BAAccount().GetAccountByUsername(model.UserName)!= null) //{ // Account account = new BAAccount().GetAccountByUsername(model.UserName); // if (model.Password != account.Password) // { // ModelState.AddModelError("", "Token is not valid."); // } // else // { // Session["accountID"] = account.ID; // return RedirectToAction("Index", "Home"); // } //} //else //{ // ModelState.AddModelError("", "Username does not exist."); //} //return RedirectToAction("Index", "Home"); }
public ActionResult UpdateUser(RegistrationModel model, Guid userID) { try { Account acc = new BAAccount().GetAccountByUsername(Session["username"].ToString()); User user = new BAUser().GetUser(userID); User u = new User(); u.ID = userID; u.Name = user.Name; u.Surname = model.Surname; u.Email = model.Email; u.HouseNumber = model.HouseNumber; u.StreetName = model.StreetName; u.TownID = user.TownID; u.AccountID = acc.ID; u.UserTypeID = (Guid)user.UserTypeID; Account a = new Account(); a.ID = acc.ID; a.Username = acc.Username; a.Password = model.Password; new BAUser().Update(u); new BAAccount().Update(a); //User user = new User(); //Account acc = new Account(); //user.Surname = model.Surname; //user.HouseNumber = model.HouseNumber; //user.StreetName = model.StreetName; //user.Email = model.Email; //acc.Password = model.Password; //BAUser baUser = new BAUser(); //BAAccount baAccount = new BAAccount(); //baUser.Update(user); //baAccount.Update(acc); return(RedirectToAction("UpdateUser")); } catch (Exception ex) { TempData["CatchError"] = "An error was encountered. Please try again later"; return(RedirectToAction("Index", model)); } }