public IActionResult RegisterAccount(RegisterViewModel model) { if (ModelState.IsValid) { User user = new User { Username = model.Username, PasswordHash = model.Password }; if (accountLogic.IsUsernameAvailable(model.Username)) { accountLogic.Add(user); } else { ModelState.AddModelError("Username", "This username already exists"); return(View("Register", model)); } } LoginViewModel vm = new LoginViewModel { Username = model.Username, Password = model.Password }; return(TryLogin(vm)); }
public void GenerateIconForNewAccount() { // Assign string expected = @"https://via.placeholder.com/50/000000/?text=A"; string actual = ""; User user = new User { Username = "******", PasswordHash = "password" }; // Act accountLogic.Add(user); actual = actual + user.ImgLocation.Substring(0, 31) + user.ImgLocation.Substring(38); // Assert Assert.Equal(expected, actual); }
public void CreateAccount() { using (var db = new DbFactory()) { var uow = new UnitOfWork(db); var repo = new GenericRepository <Account>(db); var al = new AccountLogic <Account>(uow, repo); Account a = new Account(); a.AccountName = TestUtilities.RandomString(10, false); a.SubDomain = a.AccountName.ToLower(); al.Add(a); Account b = al.GetByID(a.Id); Assert.AreEqual(b.AccountName, a.AccountName); } }
protected void btnSave_Click(object sender, EventArgs e) { AccountLogic accountLogic = new AccountLogic(); AccounModel model = new AccounModel(); bool flag = false; if (this._Action == "add") { model = this.getModel(); if (accountLogic.Add(model) > 0) { flag = true; } } else { if (this._Action == "edit") { model = this.getModel(); flag = accountLogic.Update(model); } } if (flag) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("parent.desktop.flowclass.location = '/fund/Account/PrjAccount.aspx?prjId=" + base.Request["PrjCode"] + "';"); stringBuilder.Append("alert('保存成功');"); stringBuilder.Append("top.frameWorkArea.window.desktop.getActive().close();"); base.ClientScript.RegisterClientScriptBlock(base.GetType(), "sc", "<script>" + stringBuilder.ToString() + "</script>"); return; } StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.Append("alert('保存失败');"); base.ClientScript.RegisterClientScriptBlock(base.GetType(), "sc", "<script>" + stringBuilder2.ToString() + "</script>"); }