public int GetTotalNrCopies(string isbn) { try { return(_copyDa.ReadCopies(isbn, "0", _context).Count); } catch { return(-1); } }
public List <readAllMaterial> ReadMaterials(string materialTitle, string author, int numOfRecords = 10, string isbn = "0", string jobStatus = "0") { using (var dbContextTransaction = _context.Database.BeginTransaction(IsolationLevel.ReadUncommitted)) { try { var materials = _materialDa.ReadMaterials(isbn, materialTitle, author, numOfRecords, _context); var copies = _copyDa.ReadCopies(isbn, jobStatus, _context); List <readAllMaterial> allMaterials = new List <readAllMaterial>(); readAllMaterial readAllMaterial; foreach (var c in copies) { bool unique = true; foreach (var allMaterial in allMaterials) { if (allMaterial.ISBN == c.ISBN && allMaterial.TypeName == c.TypeName && allMaterial.Location == c.LibraryName) { unique = false; } } if (unique) { foreach (var m in materials) { if (m.ISBN.Equals(c.ISBN)) { readAllMaterial = new readAllMaterial { ISBN = c.ISBN, TypeName = c.TypeName, Location = c.LibraryName, Description = m.Description, Author = m.Author, Title = m.Author }; allMaterials.Add(readAllMaterial); } } } } if (allMaterials.Count > numOfRecords) { for (int i = allMaterials.Count - 1; i >= numOfRecords; i--) { allMaterials.RemoveAt(i); } } allMaterials = CountAvailableCopies(allMaterials, copies); dbContextTransaction.Commit(); return(allMaterials); } catch { dbContextTransaction.Rollback(); return(null); } } }