public void UpdateUser(User user, string id) { var currentUser = this.users.GetById(id); currentUser.UserName = user.UserName == null ? currentUser.UserName : user.UserName; currentUser.FirstName = user.FirstName == null ? currentUser.FirstName : user.FirstName; currentUser.LastName = user.LastName == null ? currentUser.LastName : user.LastName; currentUser.Email = user.Email == null ? currentUser.Email : user.Email; currentUser.PhoneNumber = user.PhoneNumber == null ? currentUser.PhoneNumber : user.PhoneNumber; currentUser.ProfilePicture = user.ProfilePicture == null ? currentUser.ProfilePicture : user.ProfilePicture; this.users.Update(currentUser); this.users.SaveChanges(); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { Image image = null; if (model.ProfilePicture != null) { using (var memory = new MemoryStream()) { model.ProfilePicture.InputStream.CopyTo(memory); var content = memory.GetBuffer(); image = new Image { Content = content, Extension = model.ProfilePicture.FileName.Split(new[] { '.' }).Last() }; } } var user = new User { UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, SergeryLocation = model.SergeryLocation, ProfilePicture = image, Gender = model.Gender, IsVet = model.IsVet }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); if (model.IsVet) { UserManager.AddToRole(user.Id, "vet"); } else { UserManager.AddToRole(user.Id, "user"); } return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }