protected override Employee PatchEntity(int key, Delta <Employee> patch) { var employeeToPatch = GetEntityByKey(key); patch.Patch(employeeToPatch); db.Entry(employeeToPatch).State = EntityState.Modified; db.SaveChanges(); var changedProperty = patch.GetChangedPropertyNames().ToList()[0]; object changedPropertyValue; patch.TryGetPropertyValue(changedProperty, out changedPropertyValue); Hub.Clients.All.updateEmployee(employeeToPatch.Id, changedProperty, changedPropertyValue); return(employeeToPatch); }
//Add or Edit DevTest internal bool Submit(DevTest objDevtest) { if (objDevtest.Id > 0) //Edit { DevTest devTestModel; using (var _dbContext = new SignalRContext()) { devTestModel = _dbContext.DevTests.FirstOrDefault(p => p.Id == objDevtest.Id); if (devTestModel == null) { return(false); } } using (var _dbContext = new SignalRContext()) { _dbContext.Entry(objDevtest).State = System.Data.Entity.EntityState.Modified; if (_dbContext.SaveChanges() > 0) { return(true); } } } else //Add { using (var _dbContext = new SignalRContext()) { _dbContext.DevTests.Add(objDevtest); if (_dbContext.SaveChanges() > 0) { return(true); } } } return(false); }
public ActionResult Edit([Bind(Include = "userId,FirstName,LastName")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }