public void IsControllerAddingUsers() { int currCount = users.Count; db.Users.AddRange(users); db.SaveChanges(); userServices.AddUser(new User { UserName = "******", Password = "******", FirstName = "pro", LastName = "grammer", LogData = new LogData { LastTimeLoggedIn = DateTime.Now, RegisterDate = DateTime.Now, TimesLoggedIn = 1, IsOnline = true } }); db.SaveChanges(); Assert.That(currCount + 1, Is.EqualTo(db.Users.Count())); }
private void button1_Click(object sender, EventArgs e) { UserInfo user = new UserInfo(); user.Carduser = tex_card.Text; user.Cardbak = this.tb_bk.Text; user.Cardpwd = this.tex_pwd.Text; user.Cardstata = this.cmb_stata.Checked ? "是" : "否"; user.Cardtime = tex_time.Text; user.Useraddr = tex_addr.Text; user.Userbirth = tex_addr.Text; user.Userjob = tex_job.Text; // user.Userlove = tex_lo1 user.Userlove = tex_love.Text; user.Username = tex_name.Text; user.Userphone = tex_phone.Text; user.Usersex = comboBox1.SelectedText; user.Usertel = tex_tel.Text; int ret = UserServices.AddUser(user); if (ret > 0) { MessageBox.Show("添加成功!!"); this.Close(); } else { MessageBox.Show("添加失败!!"); } }
public void TestForAddUser() { //Action var IsAdded = _Userservice.AddUser(user); //Assert Assert.True(IsAdded); }
private void AddUserWithFBImage() { string response = ""; if (userServices.IsEmailIdExists(tbEmailId.Text)) { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','This Email id already has an account.')", true); } else if (tbMobileNo.Text.Length != 10) { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','Invalid Mobile No.')", true); } else { string remoteImageUrl = imgProfilePic.ImageUrl; string strRealname = Path.GetFileName(remoteImageUrl); string exts = Path.GetExtension(remoteImageUrl); WebClient webClient = new WebClient(); webClient.DownloadFile(remoteImageUrl, Server.MapPath("~/Admin/UserImages/") + strRealname + exts); //System.Drawing.Image im = System.Drawing.Image.FromFile(Server.MapPath(imgProfilePic.ImageUrl)); //im.Save(Server.MapPath("~/Admin/UserImages/" + tbEmailId.Text + ".jpg")); user.Fname = tbFname.Text; user.Lname = tbLname.Text; user.AddressLine1 = tbAddressLine1.Text; user.City = tbCity.Text; user.Province = tbProvince.Text; user.ZipCode = tbZipCode.Text; user.MobileNo = tbMobileNo.Text; user.EmailId = tbEmailId.Text; user.Password = tbPassword.Text; user.Image = "~/Admin/UserImages/" + tbEmailId.Text + ".jpg"; response = userServices.AddUser(user); if (response == "Success") { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "alert('Successfully registered.');window.location ='Login.aspx'", true); Clear(); } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','" + response + "')", true); } } }
public IActionResult Register([FromForm] AddUserModel model) { var user = new IdentityUser { UserName = model.FirstName, Email = model.Email }; userService.AddUser(model.FirstName, model.LastName, model.Email, model.Password); return(View("Register", "Index")); }
public IHttpActionResult PostUsers(Users users) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } userServices.AddUser(users); return(Ok(users)); }
public IHttpActionResult AddUser(UserModel user) { try { var result = userServices.AddUser(user); return(Ok(result)); } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, ex)); } }
public IActionResult AddUser(User user) { try { _userServices.AddUser(user); return(CreatedAtAction("AddUser", user)); } catch (Exception) { return(BadRequest()); } }
public async Task <ActionResult> AddUser([FromBody] Users user) { try { var result = await Task.Run(() => UserServices.AddUser(_context, user) ); return(CreatedAtAction("GetUsers", new { user = user.Id }, user)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; userService.AddUser(Input.FirstName, Input.LastName, Input.Email, Input.Password); var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public static void SignUp() { Console.Clear(); string username; string password; Console.WriteLine("Enter User Name : "); username = Console.ReadLine(); if (UserServices.ValidateUserName(username) == false) { Console.WriteLine("Username Already Exists!!"); Console.WriteLine("Try Again with a different username."); Console.ReadKey(); return; } Console.WriteLine("Enter Password : "); password = Console.ReadLine(); UserServices.AddUser(username, password); }
static void Main() { Console.WriteLine("Creating Database first"); //Creating database first var dropCreateDatabaseAlways = new DropCreateDatabaseAlways <BloggerDbContext>(); Database.SetInitializer(dropCreateDatabaseAlways); var context = new BloggerDbContext(); dropCreateDatabaseAlways.InitializeDatabase(context); //Creating an user Console.WriteLine("Creating an user"); IUserServices userRepository = new UserServices(); var userId = userRepository.AddUser(new VoUser { Name = "TestUser", Occupation = "Software Developer" }); //Creating a blog and its post Console.WriteLine("Creating a blog post"); IBlogServices blogRepository = new BlogServices(); var blog = new VoBlog { CreatedDateTime = DateTime.Now, Overview = "This is a sample overview.", Post = new VoPost { Meta = "Sample, Test", Content = "This is a sample overview", ShortDescription = "This is a sample short description", Title = "Test Title" }, UserId = userId }; blogRepository.AddBlog(blog); //Retrieving the user in an async mode. This is where thread switching happens Console.WriteLine("Retrieving the created user"); var user = userRepository.GetUserAsync(userId).ConfigureAwait(false); Console.WriteLine("Name of the created user is " + user.GetAwaiter().GetResult().Name); //Get the user's most recent blog Console.WriteLine("Retrieving the user most recent blog"); var recentBlog = blogRepository.GetUserRecentBlog(userId); Console.WriteLine("Overview " + recentBlog.Overview); Console.WriteLine("BlogPost Meta " + recentBlog.Post.Meta); Console.WriteLine("BlogPost Short Description " + recentBlog.Post.ShortDescription); Console.WriteLine("BlogPost Content " + recentBlog.Post.Content); //Create a blog and try to save it. If the creation fails , update the creation failure count in the user profile. var blog2 = new VoBlog { CreatedDateTime = DateTime.Now, Post = new VoPost { Meta = "Sample, Test", Content = "This is a sample overview", ShortDescription = "This is a sample short description", Title = "Test Title" }, UserId = userId }; try { blogRepository.AddBlog(blog2); } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } Console.ReadKey(); }
public ActionResultDTO Post(CloneDeployUserEntity user) { return(_userServices.AddUser(user)); }