public ActionResult RemoveUser([DataSourceRequest]DataSourceRequest request, UserModel user) { if (ModelState.IsValid) { using (var db = new GazDbContext()) { var entity = db.Users.Single(o => o.ID == user.ID); db.Users.Remove(entity); db.SaveChanges(); } } return Json(new[] { user }.ToDataSourceResult(request, ModelState)); }
public UserCounterModel(int userID) { using (var db = new GazDbContext()) { UserDetails = new UserModel(userID, db); Counters = new List<CounterModel>(); var counters = db.Users.Find(userID).User_Counters; foreach (var count in counters) { Counters.Add(new CounterModel(count)); } } }
public ActionResult AddNewUser([DataSourceRequest]DataSourceRequest request, UserModel model) { using (var db = new GazDbContext()) { db.Users.Add(new User { Email = model.Email, PhoneNumber = model.PhoneNumber, FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, RoleID = model.RoleID, Username = model.Username, }); db.SaveChanges(); } return Json(new[] { model }.ToDataSourceResult(request, ModelState)); }
public ActionResult UsersUpdate([DataSourceRequest]DataSourceRequest request, UserModel user) { if (ModelState.IsValid) { using (var db = new GazDbContext()) { var result = db.Users.Single(o => o.ID == user.ID); result.FirstName = user.FirstName; result.LastName = user.LastName; result.Password = user.Password; result.PhoneNumber = user.PhoneNumber; result.RoleID = user.RoleID; result.Email = user.Email; db.SaveChanges(); } } return Json(new[] { user }.ToDataSourceResult(request, ModelState)); }