public ActionResult Delete(int studentId) { Student student = studentRepo.Find(studentId); studentRepo.Delete(student); return(RedirectToAction("Index")); }
// DELETE api/Students/5 public void Delete(int id) { var studentToRemove = studentsRepository.All().Where(x => x.StudentIdentification == id).FirstOrDefault(); studentsRepository.Delete(studentToRemove); data.SaveChanges(); }
public async Task Delete(object id) { await StudentsRepository.Delete(id); foreach (Enrollment e in EnrollmentsRepository.GetAll().Where(e => e.StudentID == (int)id)) { await EnrollmentsRepository.Delete(e); } }
public void DeleteForm(string keyValue) { if (service.IQueryable().Count(t => t.F_Id.Equals(keyValue)) > 0) { throw new Exception("删除失败!操作的对象包含了下级数据。"); } else { service.Delete(t => t.F_Id == keyValue); } }
internal string Delete(int id) { var exists = _repo.GetById(id); if (exists == null) { throw new Exception("Invalid Id"); } _repo.Delete(id); return("Successfully Deleted"); }
/// <summary> /// 删除一个StudentsModel实体 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool DeleteOneStudentsModel(StudentsModel entity) { var result = false; try { result = dal_students.Delete(entity) > 0 ? true : false; } catch (Exception ex) { throw ex; } return(result); }
public ActionResult DeleteConfirmed(int id) { Student student = studentRepo.GetById(id); try { studentRepo.Delete(student); } catch (Exception) { ViewBag.Message = "Student " + student.FirstName + " " + student.LastName + " cannot be deleted. He has related exams. Delete exams first."; ViewBag.Related = "Go to Exams"; ViewBag.Controller = "Exams"; return(View("DeleteError")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Delete(int id) { try { var entity = await _studentsRepository.Read(id).ConfigureAwait(false); if (entity == null) { return(HttpBadRequest($"There is no student with {id} id")); } await _studentsRepository.Delete(entity).ConfigureAwait(false); return(Ok()); } catch (Exception exception) { return(HttpNotFound(exception)); } }
public void Delete() { // Arrange var repository = new StudentsRepository(new StudentsEntities()); // Act repository.Delete(2); // Assert var count = repository.All().Count(); Assert.AreEqual(1, count); }
public void DeleteStudent(Guid id) { _enrollemntsRepository.DeleteAllStudentEnrollment(id); _studentsRepository.Delete(id); _context.SaveChanges(); }