public ActionResult RegisterUser(AddUserAdminModel addUserAdminModel) { if (ModelState.IsValid == true) { string salt; string password; Utility.SetSaltAndPassword(out salt, out password, addUserAdminModel.Password); using (var db = new StudentsRegisterDataContext()) { try { var user = db.WWW_RegisterUser(addUserAdminModel.FirstName, addUserAdminModel.LastName, salt, password, DateTime.Now, StudentAccountType_Id, addUserAdminModel.Email, ref status, ref statusText) .Select(x => new UserModel() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, AccountType = x.AccountType_Id }) .ToList() .FirstOrDefault(); if (status == 0) { if (user == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } catch (Exception ex) { throw ex; } } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult RegisterUser(RegisterModel registerModel) { if (ModelState.IsValid == true) { string salt; string password; Utility.SetSaltAndPassword(out salt, out password, registerModel.Password); using (var db = new StudentsRegisterDataContext()) { try { var user = db.WWW_RegisterUser(registerModel.FirstName, registerModel.LastName, salt, password, DateTime.Now, 2, registerModel.Email, ref status, ref statusText) .Select(x => new UserModel() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, AccountType = x.AccountType_Id }) .ToList() .FirstOrDefault(); if (status == 0) { if (user == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { FormsAuthentication.SetAuthCookie(JsonConvert.SerializeObject(user), true); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } catch (Exception ex) { throw ex; } } } return(RedirectToAction("Index", "Home")); }