public ActionResult Register(UserViewModel model, HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } model.Photo = imageData; MembershipUser membershipUser = ((CustomMembershipProvider)Membership.Provider).CreateUser(model.Name, model.Password, model.Email, model.Photo); if (membershipUser != null) { return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Error"); } } return View(model); }
public ActionResult Edit(UserViewModel model) { if (ModelState.IsValid) { var blluser = new UserDTO() { UserId = model.UserId, Name = model.Name, RoleId = model.RoleId, Password = Crypto.HashPassword(model.Password), Email = model.Email, Photo = model.Photo }; service.Update(blluser); if (Roles.Provider.IsUserInRole(Membership.GetUser().UserName, "Admin")) { return RedirectToAction("DetailsForAdmin", "Users", new { id = Membership.GetUser().ProviderUserKey }); } else { FormsAuthentication.SignOut(); return RedirectToAction("Index", "Home", null); } } else { return View("Edit", model); } }