public async Task <ActionResult> Edit([Bind(Include = "Id,Email,UserName,UserRole,FirstName,LastName")] AspNetUser aspNetUser) //,[Bind(Include=("Id,Name"))] As aspNetRole ) { if (ModelState.IsValid) { db.Entry(aspNetUser).State = EntityState.Modified; // await this.UserManager.AddToRoleAsync(aspNetUser.Id, aspNetUser.UserRole = aspNetUser.UserRole); var oldUser = this.UserManager.FindById(aspNetUser.Id); var oldRoleId = oldUser.Roles.SingleOrDefault().RoleId; // var oldRoleIdFk = oldUser.UserRoleFK.SingleOrDefault(); var oldRoleIdFk = oldUser.UserRoleFK.ToString(); var oldRoleName = db.AspNetRoles.SingleOrDefault(r => r.Id == oldRoleId).Name; if (oldRoleName != aspNetUser.UserRole) { this.UserManager.RemoveFromRole(aspNetUser.Id, oldRoleName); this.UserManager.AddToRole(aspNetUser.Id, aspNetUser.UserRole); var NewRoleId = (from Role in db.AspNetRoles where Role.Name == aspNetUser.UserRole select Role.Id).SingleOrDefault(); AspNetUser User = db.AspNetUsers.Single <AspNetUser>(u => u.Id == aspNetUser.Id); User.UserRoleFK = NewRoleId; } await db.SaveChangesAsync(); return(RedirectToAction("ManageAccounts")); } return(View(aspNetUser)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,CompanyName,BirthDate,Gender,Position,Department,EmployedFrom,EmployedTo,LeaveReason,AddressLine1,AddressLine2,ZIP,Place,CountryCode")] UsersInfo userInfo) { if (ModelState.IsValid) { db.Entry(userInfo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userInfo)); }
public ActionResult Edit([Bind(Include = "Id,ItemName,Price")] StoreItem storeItem) { if (ModelState.IsValid) { storeItem.StoreIDFk = db.StoreItems.Where(d => d.Id == storeItem.Id).Select(d => d.StoreIDFk).SingleOrDefault(); db.Entry(storeItem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StoreIDFk = new SelectList(db.Stores, "Id", "StoreName", storeItem.StoreIDFk); return(View(storeItem)); }
public bool UpdateUser(int id, data user) { try { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public async Task <ActionResult> Edit([Bind(Include = "Id,StoreName,Location,ManagerIDFk,PhoneNumber")] Store store) { if (ModelState.IsValid) { store.DateOpened = db.Stores.Where(d => d.Id == store.Id).Select(d => d.DateOpened).SingleOrDefault(); db.Entry(store).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ManagerIDFk = new SelectList(db.AspNetUsers, "Id", "Email", store.ManagerIDFk); return(View(store)); }
public ActionResult Edit(User userToEdit) { var originalUser = (from u in _db.Users where u.Id == userToEdit.Id select u).First(); if (!ModelState.IsValid) { return(View(originalUser)); } _db.Entry(originalUser).CurrentValues.SetValues(userToEdit); _db.SaveChanges(); return(RedirectToAction("Index")); }