Пример #1
0
        public ActionResult CreateUser(LoginModel model)
        {
            try
            {               
                //this checks if there is valid data in the required fields On the SignUp page
                if (ModelState.IsValid)
                {
                    MongoCRUD db = new MongoCRUD("BZBugs");

                    //This checks if the username is unique or not.
                    if (db.CheckIfUsernameIsUnique<LoginModel>(model.Username) == true)
                    {
                        //Failure State    
                        ModelState.AddModelError("Username", "This Username already exists.");
                        return View("SignUp", model);
                    }                 
                    GenerateSaltedHash(model, 64, model.Password);
                    db.InsertRecord("Users", model);
                    //I want to Redirect this action to something more relevant like a Profile page or something.
                    //Success
                    return View("~/Views/Home/Profile.cshtml", model);
                }
                //Failure State
                return View("SignUp", model);               
            }
            catch
            {
                //Failure State
                return View("SignUp", model);
            }
        }