public void Insert(T entity) { SILSEntities context = CreateContext(); context.Entry(entity).State = EntityState.Added; context.SaveChanges(); }
public void Update(List <T> entities) { SILSEntities context = CreateContext(); context.Entry(entities).State = EntityState.Modified; context.SaveChanges(); }
public void Delete(T entity) { SILSEntities context = CreateContext(); context.Entry(entity).State = EntityState.Deleted; context.SaveChanges(); }
protected SILSEntities CreateContext() { SILSEntities context = new SILSEntities(); context.Configuration.ProxyCreationEnabled = false; context.Database.Log = (x) => Debug.WriteLine(x); return(context); }
public List <Library> GetByBook(int bookId) { SILSEntities context = CreateContext(); var query = from x in context.HoldingLists where x.BookId == bookId select x.Library; return(query.ToList()); }
public List <Code> GetAllReports() { SILSEntities context = CreateContext(); var query = from x in context.Codes where x.CodeId.Contains("E") select x; return(query.ToList()); }
public object GetLocation(string upperclassId = "") { SILSEntities context = CreateContext(); var qurey = from x in context.Codes where x.CodeId.Contains("L") && (x.UpperclassId == upperclassId) select x; return(qurey.ToList()); }
public List <Library> GetByLocation(string locationId) { SILSEntities context = CreateContext(); var query = from x in context.Libraries where x.LocationId == locationId select x; return(query.ToList()); }
/*public List<Book> GetAllName(string name) * { * SILSEntities context = CreateContext(); * var query = from x in context.Books * where x.Name.Contains(name) * select x; * return query.ToList(); * }*/ public List <Book> GetAllName(string name, string publisher = null, string author = null, string publishedYear = null) { SILSEntities context = CreateContext(); var query = from x in context.Books where x.Name.Contains(name) select x; List <Book> allBooks = query.ToList(); List <Book> books = new List <Book>(); if (publisher != null) { foreach (var book in allBooks) { if (book.Publisher.Contains(publisher)) { books.Add(book); } } allBooks = books; books = new List <Book>(); } if (author != null) { foreach (var book in allBooks) { if (book.Author.Contains(author)) { books.Add(book); } } allBooks = books; books = new List <Book>(); } if (publishedYear != null) { foreach (var book in allBooks) { if (book.PublicationYear.Contains(publishedYear)) { books.Add(book); } } allBooks = books; } return(allBooks); }
public List <Report> GetAllWithImfomation() { SILSEntities context = CreateContext(); var query = from x in context.Reports select new { Report = x, BookName = x.Book.Name, ReportCodeName = x.Code.Name }; var items = query.ToList(); foreach (var item in items) { item.Report.BookName = item.BookName; item.Report.ReportCodeName = item.ReportCodeName; } return(items.ConvertAll(x => x.Report)); }
/*public List<Report> GetByReportType(string codeId) * { * SILSEntities context = CreateContext(); * var query = from x in context.Reports * where x.ReportCodeId == codeId * select new { Report = x, BookName = x.Book.Name, CodeName = x.Code.Name }; * var items = query.ToList(); * * foreach (var item in items) * { * item.Report.BookName = item.BookName; * item.Report.ReportCodeName = item.CodeName; * } * return items.ConvertAll(x => x.Report); * } * * public List<Report> GetWithReported() * { * SILSEntities context = CreateContext(); * var query = from x in context.Reports * select new { Report=x, BookName=x.Book.Name, CodeName=x.Code.Name}; * var items = query.ToList(); * * foreach(var item in items) * { * item.Report.BookName = item.BookName; * item.Report.ReportCodeName = item.CodeName; * } * return items.ConvertAll(x=>x.Report); * }*/ public List <Report> GetByLibraryId(string libraryId) { SILSEntities context = CreateContext(); //var bookIdsInReport = context.Reports.Select(x => x.BookId).ToList(); var query = from x in context.HoldingLists //where x.Book.Reports.Any(r => r.BookId == x.BookId) //where bookIdsInReport.Contains(x.BookId) where x.LibraryId == libraryId select x; var query2 = from x in query.SelectMany(x => x.Book.Reports) select new { Report = x, BookName = x.Book.Name, CodeName = x.Code.Name }; var items = query2.ToList(); foreach (var item in items) { item.Report.BookName = item.BookName; item.Report.ReportCodeName = item.CodeName; } return(items.ConvertAll(x => x.Report)); //List<Book> bookqueries = Idquery.ToList(); //List<Report> reports = new List<Report>(); //foreach (Book book in bookqueries) //{ // var query = from y in context.Reports // where y.BookId == book.BookId // select new { Report = y, BookName = y.Book.Name, CodeName = y.Code.Name }; // var items = query.ToList(); // foreach (var item in items) // { // item.Report.BookName = item.BookName; // item.Report.ReportCodeName = item.CodeName; // } // reports.AddRange(items.ConvertAll(y => y.Report)); //} }
public List <Report> GetByReportCodeId(string reportCodeId) { SILSEntities context = CreateContext(); //var bookIdsInReport = context.Reports.Select(x => x.BookId).ToList(); var query = from x in context.Reports where x.ReportCodeId == reportCodeId join y in context.HoldingLists on x.BookId equals y.BookId into lib from z in lib.DefaultIfEmpty(null) //where x.Book.Reports.Any(r => r.BookId == x.BookId) //where bookIdsInReport.Contains(x.BookId) select new { Report = x, LibraryName = z == null?"":z.Library.Name, Bookname = x.Book.Name }; var items = query.ToList(); foreach (var item in items) { item.Report.LibraryName = item.LibraryName; item.Report.BookName = item.Bookname; } return(items.ConvertAll(x => x.Report)); }
public HoldingList Get(string libraryId, int bookId) { SILSEntities context = CreateContext(); return(context.HoldingLists.FirstOrDefault(a => a.BookId == bookId && a.LibraryId == libraryId)); }
public Code Get(string codeId) { SILSEntities context = CreateContext(); return(context.Codes.FirstOrDefault(a => a.CodeId == codeId)); }
public int GetCount() { SILSEntities context = CreateContext(); return(context.Set <T>().Count()); }
public Code GetByNameAndUpper(string name, string upper = "") { SILSEntities context = CreateContext(); return(context.Codes.FirstOrDefault(a => a.Name == name && a.UpperclassId == upper)); }
public Book Get(int bookId) { SILSEntities context = CreateContext(); return(context.Books.FirstOrDefault(a => a.BookId == bookId)); }
public List <T> GetAll() { SILSEntities context = CreateContext(); return(context.Set <T>().ToList()); }
public Book GetbyISBN(string isbn) { SILSEntities context = CreateContext(); return(context.Books.FirstOrDefault(a => a.ISBN == isbn)); }
public Book GetName(string name) { SILSEntities context = CreateContext(); return(context.Books.FirstOrDefault(a => a.Name == name)); }
public Library GetName(string name) { SILSEntities context = CreateContext(); return(context.Libraries.FirstOrDefault(a => a.Name == name)); }
public Library Get(string libraryId) { SILSEntities context = CreateContext(); return(context.Libraries.FirstOrDefault(a => a.LibraryId == libraryId)); }
public Report Get(int reportId) { SILSEntities context = CreateContext(); return(context.Reports.FirstOrDefault(a => a.ReportId == reportId)); }