public int Delete(User user) { try { _dbContext.User.Add(user); _dbContext.Entry(user).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public int DeleteType(FeeType feetype) { try { _dbContext.FeeType.Add(feetype); _dbContext.Entry(feetype).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public int DeleteLocation(Location loc) { try { _dbContext.Location.Add(loc); _dbContext.Entry(loc).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public int Delete(Class classes) { try { _dbContext.Class.Add(classes); _dbContext.Entry(classes).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public int ReAdmission(Student student) { try { _dbContext.Student.Add(student); _dbContext.Entry(student).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
//public Model.Response.ServiceResponseWithResultset<Model.Model.GenderModel> GetAll() //{ // try // { // var result = this._context.proc_Gender_GetAll().ToList(); // List<GenderModel> collection = new List<GenderModel>(); // foreach (var item in result) // { // collection.Add(new GenderModel // { // GenderDescription=item.genderDescription, // GenderId = item.genderId, // GenderLetter=item.genderLetter // }); // } // return new ServiceResponseWithResultset<GenderModel> // { // Response = Model.Enumerator.Enum.ServiceResponses.Success, // Reason = "OK", // Data = collection // }; // } // catch (Exception ex) // { // return new ServiceResponseWithResultset<GenderModel> // { // Response = Model.Enumerator.Enum.ServiceResponses.Failure, // Reason = "Error on GetAll method. " + ex.InnerException != null ? ex.InnerException.Message : ex.Message // }; // } //} //public IQueryable<Model.Model.GenderModel> FindBy(Model.Model.GenderModel entity) //{ // throw new NotImplementedException(); //} //public Model.Response.SaveResult Add(Model.Model.GenderModel entity) //{ // throw new NotImplementedException(); //} //public Model.Response.SaveResult Delete(Model.Model.GenderModel entity) //{ // throw new NotImplementedException(); //} //public Model.Response.SaveResult Edit(Model.Model.GenderModel entity) //{ // throw new NotImplementedException(); //} //public void Dispose() //{ // throw new NotImplementedException(); //} public SaveResult Add(List <PeriodGradeModel> periodGradeModelList) { try { foreach (var item in periodGradeModelList) { var periodGradeToAdd = new PeriodGrade { gradeId = item.GradeModel.GradeId, periodId = item.PeriodModel.PeriodId }; _context.Entry(periodGradeToAdd).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } return(new SaveResult { Message = "Period Grades selected was created successfully!", Status = "OK" }); } catch (Exception ex) { return(new SaveResult { Message = "Error on PeriodGrade Add method. " + ex.InnerException != null ? ex.InnerException.Message : ex.Message, Status = "ERROR" }); } }
public ActionResult Edit([Bind(Include = "DepartmentId,Name,StartDate,Administrator")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Edit([Bind(Include = "ID,Name,Address,Email,Class")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Edit([Bind(Include = "ClassID,ClassName")] Class @class) { if (ModelState.IsValid) { db.Entry(@class).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@class)); }
public ActionResult Edit(Person people) { var db = new SchoolEntities(); if (ModelState.IsValid) { db.Entry(people).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("StudentGradeManagement")); } return(View(people)); }
public int Delete(Role role) { try { _dbContext.Role.Add(role); _dbContext.Entry(role).State = EntityState.Modified; return(_dbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public ActionResult Edit([Bind(Include = "st_id,fullname,gender,birth_date,phone")] Student student) { student.fullname = Remove_Successive_spaces(student.fullname); if (ModelState.IsValid) { int x; int.TryParse(Session["id"].ToString(), out x); student.father_id = x; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("StudentList")); }
public ActionResult Delete(int id) { using (SchoolEntities dbContext = new SchoolEntities()) { Student targetStudent = dbContext.Students.SingleOrDefault(m => m.Id == id); if (targetStudent != null) { dbContext.Entry(targetStudent).State = System.Data.Entity.EntityState.Deleted; //dbContext.Students.Remove(targetStudent); dbContext.SaveChanges(); } } return(RedirectToAction("Show")); }
public ActionResult Delete(Teacher teacher) { using (SchoolEntities dbContext = new SchoolEntities()) { if (teacher != null) { dbContext.Entry(teacher).State = System.Data.Entity.EntityState.Deleted; dbContext.SaveChanges(); } //dbContext.Teachers.Remove(teacher); //dbContext.SaveChanges(); //Have problem to run ,because the foreign key, have to delete the student, then you can delete the teacher. } return(RedirectToAction("Show")); }
public void Delete(T entity) { var entry = _context.Entry(entity); if (entry.State == EntityState.Detached) { _context.Set <T>().Attach(entity); } _context.Set <T>().Remove(entity); _context.SaveChanges(); }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid student id")); } using (var ctx = new SchoolEntities()) { var student = ctx.Students .Where(s => s.StudentId == id) .FirstOrDefault(); ctx.Entry(student).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } return(Ok()); }
//Delete public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid student id")); } var student = db.Students .Where(s => s.StudentID == id) .FirstOrDefault(); db.Entry(student).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(Ok()); }
public void ConcurrentUpdate_ClientWins() { using (new TransactionScope()) { using (var context1 = new SchoolEntities()) using (var context2 = new SchoolEntities()) { var p1 = context1.People.Find(1); var p2 = context2.People.Find(1); p1.FirstName = "UPDATE"; context1.SaveChanges(); try { p2.FirstName = "SOMETHING ELSE"; context2.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); entry.OriginalValues.SetValues(entry.GetDatabaseValues()); context2.SaveChanges(); } Assert.AreEqual(p2.FirstName, "SOMETHING ELSE"); Assert.AreEqual(EntityState.Unchanged, context2.Entry(p2).State); context2.SaveChanges(); } using (var context = new SchoolEntities()) { Assert.AreEqual("SOMETHING ELSE", context.People.Find(1).FirstName); } } }
public void ConcurrentUpdate_DatabaseWins() { using (new TransactionScope()) { using (var context1 = new SchoolEntities()) using (var context2 = new SchoolEntities()) { var p1 = context1.People.Find(1); var p2 = context2.People.Find(1); p1.FirstName = "UPDATE"; context1.SaveChanges(); try { p2.FirstName = "SOMETHING ELSE"; context2.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { // Refreshes the tracked entities with new values from the database. ex.Entries.Single().Reload(); } Assert.AreEqual(p2.FirstName, "UPDATE"); Assert.AreEqual(EntityState.Unchanged, context2.Entry(p2).State); context2.SaveChanges(); } using (var context = new SchoolEntities()) { Assert.AreEqual("UPDATE", context.People.Find(1).FirstName); } } }
public void DetachedEntities_ShouldBe_AddedBeforeSaveChanges() { Person pietje = null; // Die scope werkt dus ook over contexten heen! using (new TransactionScope()) { using (var context = new SchoolEntities()) { // AsNoTracking zorgt ervoor dat de ChangeTracker buitenspel wordt gezet. pietje = context.People.AsNoTracking().First(p => p.PersonID == 33); } pietje.LastName = "AS NO TRACKING"; using (var context = new SchoolEntities()) { // Slecht idee, twee pietjes in de DB //context.People.Add(pietje); context.Entry(pietje).State = EntityState.Modified; context.SaveChanges(); } } }
public void ConcurrentUpdate_ClietnChooses() { using (new TransactionScope()) { using (var context1 = new SchoolEntities()) using (var context2 = new SchoolEntities()) { var p1 = context1.People.Find(1); var p2 = context2.People.Find(1); p1.FirstName = p1.LastName = "UPDATE"; context1.SaveChanges(); try { p2.FirstName = p2.LastName = "SOMETHING ELSE"; context2.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var current = entry.CurrentValues; var other = entry.GetDatabaseValues(); var resolved = other.Clone(); ClientChooses(current, other, resolved); entry.OriginalValues.SetValues(other); entry.CurrentValues.SetValues(resolved); context2.SaveChanges(); } Assert.AreEqual(p2.FirstName, "UPDATE"); Assert.AreEqual(p2.LastName, "SOMETHING ELSE"); Assert.AreEqual(EntityState.Unchanged, context2.Entry(p2).State); context2.SaveChanges(); } using (var context = new SchoolEntities()) { var p = context.People.Find(1); Assert.AreEqual("UPDATE", p.FirstName); Assert.AreEqual("SOMETHING ELSE", p.LastName); } } }