Exemplo n.º 1
0
        public void Insert(T entity)
        {
            SILSEntities context = CreateContext();

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

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

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

            context.Configuration.ProxyCreationEnabled = false;
            context.Database.Log = (x) => Debug.WriteLine(x);
            return(context);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
            //}
        }
Exemplo n.º 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));
        }
Exemplo n.º 13
0
        public HoldingList Get(string libraryId, int bookId)
        {
            SILSEntities context = CreateContext();

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

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

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

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

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

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

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

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

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

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

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