Example #1
0
        public void Insert(T entity)
        {
            SILSEntities context = CreateContext();

            context.Entry(entity).State = EntityState.Added;
            context.SaveChanges();
        }
Example #2
0
        public void Update(List <T> entities)
        {
            SILSEntities context = CreateContext();

            context.Entry(entities).State = EntityState.Modified;
            context.SaveChanges();
        }
Example #3
0
        public void Delete(T entity)
        {
            SILSEntities context = CreateContext();

            context.Entry(entity).State = EntityState.Deleted;
            context.SaveChanges();
        }
Example #4
0
        protected SILSEntities CreateContext()
        {
            SILSEntities context = new SILSEntities();

            context.Configuration.ProxyCreationEnabled = false;
            context.Database.Log = (x) => Debug.WriteLine(x);
            return(context);
        }
Example #5
0
        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());
        }
Example #6
0
        public List <Code> GetAllReports()
        {
            SILSEntities context = CreateContext();
            var          query   = from x in context.Codes
                                   where x.CodeId.Contains("E")
                                   select x;

            return(query.ToList());
        }
Example #7
0
        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());
        }
Example #8
0
        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());
        }
Example #9
0
        /*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);
        }
Example #10
0
        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));
        }
Example #11
0
        /*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));
            //}
        }
Example #12
0
        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));
        }
Example #13
0
        public HoldingList Get(string libraryId, int bookId)
        {
            SILSEntities context = CreateContext();

            return(context.HoldingLists.FirstOrDefault(a => a.BookId == bookId && a.LibraryId == libraryId));
        }
Example #14
0
        public Code Get(string codeId)
        {
            SILSEntities context = CreateContext();

            return(context.Codes.FirstOrDefault(a => a.CodeId == codeId));
        }
Example #15
0
        public int GetCount()
        {
            SILSEntities context = CreateContext();

            return(context.Set <T>().Count());
        }
Example #16
0
        public Code GetByNameAndUpper(string name, string upper = "")
        {
            SILSEntities context = CreateContext();

            return(context.Codes.FirstOrDefault(a => a.Name == name && a.UpperclassId == upper));
        }
Example #17
0
        public Book Get(int bookId)
        {
            SILSEntities context = CreateContext();

            return(context.Books.FirstOrDefault(a => a.BookId == bookId));
        }
Example #18
0
        public List <T> GetAll()
        {
            SILSEntities context = CreateContext();

            return(context.Set <T>().ToList());
        }
Example #19
0
        public Book GetbyISBN(string isbn)
        {
            SILSEntities context = CreateContext();

            return(context.Books.FirstOrDefault(a => a.ISBN == isbn));
        }
Example #20
0
        public Book GetName(string name)
        {
            SILSEntities context = CreateContext();

            return(context.Books.FirstOrDefault(a => a.Name == name));
        }
Example #21
0
        public Library GetName(string name)
        {
            SILSEntities context = CreateContext();

            return(context.Libraries.FirstOrDefault(a => a.Name == name));
        }
Example #22
0
        public Library Get(string libraryId)
        {
            SILSEntities context = CreateContext();

            return(context.Libraries.FirstOrDefault(a => a.LibraryId == libraryId));
        }
Example #23
0
        public Report Get(int reportId)
        {
            SILSEntities context = CreateContext();

            return(context.Reports.FirstOrDefault(a => a.ReportId == reportId));
        }