public bool Delete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { SubType result = unitOfWork.SubTypeRepository.GetById(id); if (result == null) { return(false); } if (result.Title.Equals("Unsorted")) { return(true); } TorrentService torrentService = new TorrentService(); List <TorrentDto> torrents = torrentService.GetAllBySubTypeWithDeleted(id).ToList(); CatalogDto unsortedC = catalogService.GetAllWithTitle("Unsorted").FirstOrDefault(); SubTypeDto unsortedS = GetAllWithTitle(unsortedC.Id, "Unsorted").FirstOrDefault(); foreach (var item in torrents) { item.Catalog = unsortedC; item.SybType = unsortedS; torrentService.Update(item); } unitOfWork.SubTypeRepository.Delete(result); return(unitOfWork.Save()); } }
public bool FakeDelete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { Catalog result = unitOfWork.CatalogRepository.GetById(id); if (result == null) { return(false); } if (result.Title.Equals("Unsorted")) { return(true); } TorrentService torrentService = new TorrentService(); SubTypeService subTypeService = new SubTypeService(); List <TorrentDto> torrents = torrentService.GetAllByCatalogWithDeleted(id).ToList(); CatalogDto unsortedC = GetAllWithTitle("Unsorted").FirstOrDefault(); SubTypeDto unsortedS = subTypeService.GetAllWithTitle(unsortedC.Id, "Unsorted").FirstOrDefault(); foreach (var item in torrents) { item.Catalog = unsortedC; item.SybType = unsortedS; torrentService.Update(item); } foreach (var item in subTypeService.GetAllByCatalog(result.Id)) { item.IsDeleted = true; item.DeletedOn = DateTime.Now; subTypeService.Update(item); } result.IsDeleted = true; result.DeletedOn = DateTime.Now; unitOfWork.CatalogRepository.Update(result); return(unitOfWork.Save()); } }
public bool Delete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { User result = unitOfWork.UserRepository.GetById(id); if (result == null) { return(false); } if (result.Username.Equals("deleted")) { return(true); } TorrentService torrentService = new TorrentService(); List <TorrentDto> torrentList = torrentService.GetAllByUploaderWithDeleted(id).ToList(); UserDto deleted = GetAllWithUsername("deleted").FirstOrDefault(); foreach (var item in torrentList) { item.Uploader = deleted; torrentService.Update(item); } UserToTorrentService userToTorrentService = new UserToTorrentService(); List <UserToTorrentDto> list = userToTorrentService.GetAll().Where(us => us.Downloader.Id == id).ToList(); foreach (var item in list) { userToTorrentService.Delete(item.Id); } unitOfWork.UserRepository.Delete(result); return(unitOfWork.Save()); } }