public IHttpActionResult PutUserTable(int id, UserTable userTable) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userTable.UserId) { return(BadRequest()); } userDb.Entry(userTable).State = EntityState.Modified; try { UserCrypt crypt = new UserCrypt(); userTable.UserPass = crypt.EncryptPass(userTable.UserPass); userDb.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserTableExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "UserId,UserName,UserGender,UserDep,UserAdmNo,UserEmail,UserPass")] tblUser tblUser) { if (ModelState.IsValid) { Session["operationMsg"] = "User updated successfully"; userDb.Entry(tblUser).State = EntityState.Modified; userDb.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblUser)); }
public void Update(User data) { try { using (_userEnt = new UserEntity()) { _userEnt.Users.Attach(data); _userEnt.Entry <User>(data).State = System.Data.EntityState.Modified; _userEnt.SaveChanges(); } } catch { } }
public void Delete(int id) { try { using (_userEnt = new UserEntity()) { var usr = _userEnt.Users.Find(id); _userEnt.Users.Attach(usr); _userEnt.Entry <User>(usr).State = System.Data.EntityState.Deleted; _userEnt.SaveChanges();; } } catch { } }
public AspNetUsers SerUserForOrder(AspNetUsers user, int userRoleId = (int)UserRoles.none) { //try { AspNetUsers us; user.AspNetRoles.Add(GetUserRole(userRoleId)); if ((us = Userdb.AspNetUsers.Where(u => String.Compare(u.Email, user.Email) == 0 || String.Compare(u.UserName, user.UserName) == 0).AsNoTracking().FirstOrDefault()) == null) { Userdb.AspNetUsers.Add(user); Userdb.Entry(user).State = EntityState.Added; Userdb.SaveChanges(); } return(us == null ? user : us); } //catch (Exception ex) { //throw null; } }