public ActionResult Edit(int id, EditViewModels e, HttpPostedFileBase file) { try { if (file != null) { var bs = new byte[file.ContentLength]; using (var fs = file.InputStream) { var offset = 0; do { offset += fs.Read(bs, offset, bs.Length - offset); } while (offset < bs.Length); } DLSInterface.image = bs; return(View()); } else { SE_ProjectEntities db = new SE_ProjectEntities(); db.Posts.Find(id).Summary = e.summary; db.Posts.Find(id).Details = e.details; db.Posts.Find(id).Picture = DLSInterface.image; db.SaveChanges(); DLSInterface.image = null; return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult Edit(string id) { var ur = new UserRepository(); using (var db = new DataContext()) { var user = db.Users.FirstOrDefault(u => u.Id.Equals(id)); var editViewModel = new EditViewModels(user); return(View(editViewModel)); } }
// GET: Post/Edit/5 public ActionResult Edit(int id) { EditViewModels l = new EditViewModels(); SE_ProjectEntities db = new SE_ProjectEntities(); Post p = db.Posts.Find(id); DLSInterface.image = p.Picture; l.summary = p.Summary; l.details = p.Details; return(View(l)); }
public ActionResult Edit(int?id) { var ordemServico = this.Contexto.OrdemServicos.FirstOrDefault(_ => _.OrdemServicoID == id); var situacao = this.Contexto.Situacaos.ToList(); ViewBag.SituacaoID = new SelectList( this.Contexto.Situacaos.ToList(), "SituacaoID", "Nome" ); var model = new EditViewModels(ordemServico, situacao); return(View(model)); }
public async Task <ActionResult> Edit(EditViewModels model) { if (ModelState.IsValid) { using (DataContext db = new DataContext()) { var id = Url.RequestContext.RouteData.Values["id"].ToString(); var user = db.Users.FirstOrDefault(u => u.Id.Equals(id)); UserRepository ur = new UserRepository(); //if (!user.Id.Equals(User.Identity.GetUserId())) //{ // user.Admin = model.applicationUser.Admin; //} bool someTypeOfAdmin = false; if (model.Admin) { ur.AddUserToRole(user.Email, "administrator"); someTypeOfAdmin = true; } else { if (user.Id.Equals(System.Web.HttpContext.Current.User.Identity.GetUserId())) { ur.AddUserToRole(user.Email, "administrator"); someTypeOfAdmin = true; } else { ur.RemoveUserFromRole(user.Email, "administrator"); } } if (model.EducationAdmin) { ur.AddUserToRole(user.Email, "educationAdministrator"); someTypeOfAdmin = true; } else { ur.RemoveUserFromRole(user.Email, "educationAdministrator"); } if (model.ResarchAdmin) { ur.AddUserToRole(user.Email, "researchAdministrator"); someTypeOfAdmin = true; } else { ur.RemoveUserFromRole(user.Email, "researchAdministrator"); } if (!someTypeOfAdmin) { ur.AddUserToRole(user.Email, "user"); } else { ur.RemoveUserFromRole(user.Email, "user"); } if (model.FirstName != null) { user.FirstName = model.FirstName; } if (model.LastName != null) { user.LastName = model.LastName; } if (model.Email != null && !model.Email.Equals(user.Email)) { user.Email = model.Email; user.UserName = model.Email; } if (model.setPassword.NewPassword != null) { String userId = user.Id; String newPassword = model.setPassword.NewPassword; String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword); UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(); await store.SetPasswordHashAsync(user, hashedNewPassword); } //if (ModelState.IsValid) //{ // //var resultDeletePass = UserManager.RemovePassword(user.Id); // //var resultPass = UserManager.AddPassword(User.Identity.GetUserId(), model.setPassword.NewPassword); // //if (resultPass.Succeeded) // //{ // // var userPass = await UserManager.FindByIdAsync(User.Identity.GetUserId()); // // if (userPass != null) // // { // // await SignInManager.SignInAsync(userPass, isPersistent: false, rememberBrowser: false); // // } // // return RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess }); // //} // AddErrors(resultDeletePass); // AddErrors(resultPass); //} try { db.SaveChanges(); } catch { ModelState.AddModelError("", "User with that email already exists"); return(View(model)); } //var result = await UserManager.UpdateAsync(user); } return(RedirectToAction("Adminpanel", "Admin")); } return(View(model)); }