public bool Delete(UserEntity userEntity, Guid StudentId) { StudentLecturer studentLecturer = IMSContext.StudentLecturers.Where(sl => sl.StudentId == StudentId).FirstOrDefault(); if (studentLecturer == null) { throw new BadRequestException("StudentLecturer không tồn tại!"); } IMSContext.Remove(studentLecturer); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity userEntity, Guid Id) { Admin admin = IMSContext.Admins.Where(a => a.Id == Id).FirstOrDefault(); if (admin == null) { throw new BadRequestException("Admin không tồn tại!"); } IMSContext.Remove(admin); IMSContext.SaveChanges(); return(true); }
public bool Delete(UserEntity UserEntity, Guid internNewsId) { InternNews internNews = IMSContext.InternNews.Where(s => s.Id == internNewsId).FirstOrDefault(); if (internNews == null) { return(false); } IMSContext.Remove(internNews); IMSContext.SaveChanges(); return(true); }
public bool Delete(Guid internNewsId) { InternNews internNews = IMSContext.InternNews .Where(s => s.Id == internNewsId) .Include(i => i.InternFollows) .FirstOrDefault(); if (internNews == null) { return(false); } foreach (var item in internNews.InternFollows) { IMSContext.Remove(item); } IMSContext.SaveChanges(); IMSContext.Remove(internNews); IMSContext.SaveChanges(); return(true); }
public override bool Delete(Employee employee) { if (employee == null) { return(false); } foreach (var x in _context.EmployeeInventories .Where(x => x.EmployeeId == employee.Id).ToList()) { _context.Remove(x); } foreach (var x in _context.EmployeeSalaries .Where(x => x.EmployeeId == employee.Id).ToList()) { _context.Remove(x); } _context.SaveChanges(); Address address = _context.Addresses.Find(employee.AddressId); _context.Remove(address); ApplicationUser user = _context.Users .Where(x => x.UserName == employee.Username).FirstOrDefault(); ApplicationUserRole userRole = _context.UserRoles .Where(x => x.UserId == user.Id).FirstOrDefault(); Person person = _context.Persons .Where(x => x.IdentityUserId == user.Id).FirstOrDefault(); if (user != null) { _context.Remove(userRole); _context.Remove(person); _context.Remove(user); } //_context.Remove(employee); //_context.SaveChanges(); return(base.Delete(employee)); }