示例#1
0
 //almost certainly not right! too heavy
 public static IEnumerable <Item> GetAllItems()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         return(AllItems(ctx).OrderBy(item => item.Title).ToList());
     }
 }
示例#2
0
 static public IEnumerable <Event> GetEvents()
 {
     using (var context = new LibraryDataContext())
     {
         return(context.Events.ToList());
     }
 }
示例#3
0
 static public int GetAllEventsNumber()
 {
     using (var context = new LibraryDataContext())
     {
         return(context.Events.Count());
     }
 }
示例#4
0
 public static void Initialize(LibraryDataContext db)
 {
     db.Books.AddRange(
         GetSeedingBooks()
         );
     db.SaveChanges();
 }
示例#5
0
 //almost certainly not right! too heavy
 public static IEnumerable<Item> GetAllItems()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         return AllItems(ctx).OrderBy(item => item.Title).ToList();
     }
 }
示例#6
0
 private void checkUser()
 {
     if (Session["CurrentUser"] != null)
     {
         //lblCurrentUser.Text = ((Manager)Session["CurrentUser"]).Name;
         if (!Request.Url.AbsoluteUri.ToLower().Contains("default.aspx"))
         {
             Int64 nUserID         = ((Eza)Session["CurrentUser"]).ID;
             LibraryDataContext dc = new LibraryDataContext();
             var pages             = from p in dc.WebPages
                                     join r in dc.UserRoles
                                     on p.ID equals r.PageID
                                     where r.UserID == nUserID
                                     select p.PageFile;
             int    nStartIndex = Request.Url.AbsoluteUri.ToLower().LastIndexOf('/') + 1;
             int    nEndIndex   = Request.Url.AbsoluteUri.ToLower().LastIndexOf(".aspx");
             string strFileName = Request.Url.AbsoluteUri.ToLower().Substring(nStartIndex, nEndIndex - nStartIndex + 5);
             if (!pages.Contains(strFileName))
             {
                 Response.Redirect("Main.aspx");
             }
         }
     }
     else
     {
         //pnlSideBar.Visible = false;
         if (!Request.Url.AbsoluteUri.ToLower().Contains("default.aspx"))
         {
             Response.Redirect("Default.aspx");
         }
     }
 }
        private void UpdateLentBooks(LibraryDataContext dataContext, DB.Lending currentEntity, Model.Lending modifiedEntity)
        {
            DB.Employee currentEmployee = GetCurrentEmployee(dataContext);
            var         newListOfBooks  = modifiedEntity.Books.ToList();

            foreach (DB.LentBook book in currentEntity.Books.ToList())
            {
                newListOfBooks.RemoveFirst(x => x.Id == book.Id);
                Model.LentBook newBook = modifiedEntity.Books.FirstOrDefault(x => x.Id == book.Id);

                if (newBook == null) //removed
                {
                    currentEntity.Books.Remove(book);
                    dataContext.LentBooks.Remove(book);
                }
                else //modified
                {
                    UpdateSingleLentBook(book, newBook, currentEmployee);
                }
            }

            //add new LentBooks
            foreach (Model.LentBook book in newListOfBooks)
            {
                DB.LentBook toAdd = Mapper.Map <DB.LentBook>(book);
                toAdd.Lending        = currentEntity;
                toAdd.ReturnEmployee = (book.ReturnDate != null) ? currentEmployee : null;
                currentEntity.Books.Add(toAdd);
            }
        }
示例#8
0
    protected void gvReplaies_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LibraryDataContext lib = new LibraryDataContext();

        if (e.CommandName == "confrim")
        {
            Response.Write("confirim");
            int nid = Convert.ToInt32(gvReplaies.Rows[Convert.ToInt32(e.CommandArgument)].Cells[1].Text);
            Response.Write(nid.ToString());
            Replay rep = (from rp in lib.Replays
                          where rp.ID == nid
                          select rp).SingleOrDefault();

            rep.Enable = Convert.ToBoolean(rep.Enable) ? false : true;
            lib.SubmitChanges();
        }
        else if (e.CommandName == "delete")
        {
            int nid = Convert.ToInt32(gvReplaies.Rows[Convert.ToInt32(e.CommandArgument)].Cells[1].Text);
            Response.Write(nid.ToString());
            Replay rep = (from rp in lib.Replays
                          where rp.ID == nid
                          select rp).SingleOrDefault();
            rep.Deleted = Convert.ToBoolean(rep.Deleted) ? false : true;
            lib.SubmitChanges();
        }
        gvReplaies.DataBind();
        Response.Write(" ca:" + e.CommandArgument.ToString());
    }
 public ReservationsController(IMapper mapper, LibraryDataContext context, MapperConfiguration config, IProccessReservation reservationProcessor)
 {
     _mapper  = mapper;
     _context = context;
     _config  = config;
     _reservationProcessor = reservationProcessor;
 }
示例#10
0
 public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILogger <BooksController> logger)
 {
     _context = context;
     _mapper  = mapper;
     _config  = config;
     _logger  = logger;
 }
示例#11
0
 public IEnumerable <Reader> GetReaders()
 {
     using (var context = new LibraryDataContext())
     {
         return(context.Readers.ToList());
     }
 }
示例#12
0
 static public IEnumerable <Book> GetBooksByGenre(string g)
 {
     using (var context = new LibraryDataContext())
     {
         return(context.Books.Where(book => book.genre.Equals(g)).ToList());
     }
 }
示例#13
0
        public static void ReinitializeDb(LibraryDataContext db)
        {
            db.Books.RemoveRange(db.Books); // delete all the books.
            var x = db.SaveChangesAsync().Result;

            Initialize(db);
        }
示例#14
0
        protected void UpdateCollection <ModelType, DBModelType>(LibraryDataContext dataContext, ICollection <ModelType> source, ICollection <DBModelType> destination)
            where ModelType : class, Model.IIdRecord
            where DBModelType : class, DB.IIdRecord
        {
            //removed items
            foreach (var oldItem in destination.ToList())
            {
                if (!source.Any(x => x.Id == oldItem.Id))
                {
                    destination.Remove(oldItem);
                }
            }

            //added items
            foreach (var newItem in source)
            {
                if (!destination.Any(x => x.Id == newItem.Id))
                {
                    var toAdd = dataContext.Set <DBModelType>().FirstOrDefault(x => x.Id == newItem.Id);
                    if (toAdd != null)
                    {
                        destination.Add(toAdd);
                    }
                }
            }
        }
 public void Store(LibraryDataContext libraryDataContext)
 {
     if (_libraryDataContexts.Contains(GetThreadName()))
         _libraryDataContexts[GetThreadName()] = libraryDataContext;
     else
         _libraryDataContexts.Add(GetThreadName(), libraryDataContext);           
 }
示例#16
0
 public BooksController(
     LibraryDataContext context,
     IMapBooks mapper)
 {
     Context = context;
     Mapper  = mapper;
 }
示例#17
0
 protected void CreateDatabaseIfNotExists()
 {
     using (var dataContext = new LibraryDataContext(_connectionString))
     {
         dataContext.Database.CreateIfNotExists();
     }
 }
示例#18
0
 public static IEnumerable <Lookup> GetAllLookups()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         return(ctx.Lookups.ToList());
     }
 }
 public void Store(LibraryDataContext libraryDataContext)
 {
     if (HttpContext.Current.Items.Contains(_dataContextKey))
         HttpContext.Current.Items[_dataContextKey] = libraryDataContext;
     else
         HttpContext.Current.Items.Add(_dataContextKey, libraryDataContext);  
 }
示例#20
0
 public void Store(LibraryDataContext libraryDataContext)
 {
     if (_libraryDataContexts.Contains(GetThreadName()))
         _libraryDataContexts[GetThreadName()] = libraryDataContext;
     else
         _libraryDataContexts.Add(GetThreadName(), libraryDataContext);
 }
示例#21
0
 public ReservationsController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILogReservations reservationLogger)
 {
     _context           = context;
     _mapper            = mapper;
     _config            = config;
     _reservationLogger = reservationLogger;
 }
示例#22
0
 public static IEnumerable<Lookup> GetAllLookups()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         return ctx.Lookups.ToList();
     }
 }
示例#23
0
 public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILookupBooks bookLookup, IBookCommands bookCommands)
 {
     _context      = context;
     _mapper       = mapper;
     _config       = config;
     _bookLookup   = bookLookup;
     _bookCommands = bookCommands;
 }
示例#24
0
 public static void AddAuthor(Data.Author author)
 {
     using (Data.LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Authors.Add(author);
         ctx.SaveChanges();
     }
 }
示例#25
0
 public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration mapperConfig, IQueryForBooks booksQuery, IDoBookCommands bookCommands)
 {
     _context      = context;
     _mapper       = mapper;
     _mapperConfig = mapperConfig;
     _booksQuery   = booksQuery;
     _bookCommands = bookCommands;
 }
示例#26
0
 public static void AddPatron(Patron patron)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Patrons.Add(patron);
         ctx.SaveChanges();
     }
 }
示例#27
0
 private static IQueryable <Item> AllItems(LibraryDataContext ctx)
 {
     return(ctx.Items.Include(item => item.Authors)
            .Include(item => item.Editions.Select(edition => edition.Copies))
            .Include(item => item.ItemSubjects)
            .Include(item => item.Reserves)
            .Where(item => !item.Deleted));
 }
示例#28
0
 private static IQueryable<Item> AllItems(LibraryDataContext ctx)
 {
     return ctx.Items.Include(item => item.Authors)
                     .Include(item => item.Editions.Select(edition => edition.Copies))
                     .Include(item => item.ItemSubjects)
                     .Include(item => item.Reserves)
                     .Where(item => !item.Deleted);
 }
示例#29
0
        private LibraryDataContext GetDataContext()
        {
            var dataContext = new LibraryDataContext(_connectionString);

            dataContext.Database.CreateIfNotExists();

            return(dataContext);
        }
示例#30
0
 public static void AddPublisher(Publisher publisher)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Publishers.Add(publisher);
         ctx.SaveChanges();
     }
 }
示例#31
0
 public void SelectBookWhichNotExistsFromDatabase()
 {
     using (var db = new LibraryDataContext())
     {
         Book book = db.Books.FirstOrDefault(b => b.title.Equals("Harry -------- Potter"));
         Assert.IsNull(book);
     }
 }
示例#32
0
 public static void AddPatron(Patron patron)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Patrons.Add(patron);
         ctx.SaveChanges();
     }
 }
示例#33
0
 public IEnumerable <Book> GetAllBooks()
 {
     using (var context = new LibraryDataContext())  //inside using it gets closed automatically
     {
         var result = context.Books.ToList();
         return(result);
     }
 }
示例#34
0
 public static void AddAuthor(Data.Author author)
 {
     using (Data.LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Authors.Add(author);
         ctx.SaveChanges();
     }
 }
示例#35
0
 public static void Update(Lookup lookup)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Lookups.Attach(lookup);
         ctx.Entry(lookup).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#36
0
 public static void DeletePatron(long id)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         Patron toDelete = ctx.Patrons.Find(id);
         ctx.Patrons.Remove(toDelete);
         ctx.SaveChanges();
     }
 }
示例#37
0
 public static void UpdatePatron(Patron patron)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Patrons.Attach(patron);
         ctx.Entry(patron).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#38
0
 public static void DeleteAuthor(long id)
 {
     using (Data.LibraryDataContext ctx = new LibraryDataContext())
     {
         Author a = ctx.Authors.Find(id);
         ctx.Authors.Remove(a);
         ctx.SaveChanges();
     }
 }
示例#39
0
 public static void DeletePublisher(long publisherID)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         Publisher publisher = ctx.Publishers.Find(publisherID);
         ctx.Publishers.Remove(publisher);
         ctx.SaveChanges();
     }
 }
示例#40
0
 public static void UpdatePublisher(Publisher persistentPublisher)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Publishers.Attach(persistentPublisher);
         ctx.Entry(persistentPublisher).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#41
0
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);

            DataContext = new LibraryDataContext();

            InitializeCurrentUser(controllerContext.Request);
            InitializeCurrentVisitor(controllerContext.Request);
        }
示例#42
0
 public static void UpdateAuthor(Author author)
 {
     using (Data.LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Authors.Attach(author);
         ctx.Entry(author).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#43
0
        public DashboardController(LibraryDataContext context)
        {
            appDbContext = context;

            serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
        }
示例#44
0
 public static void UpdatePatron(Patron patron)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         ctx.Patrons.Attach(patron);
         ctx.Entry(patron).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#45
0
 public static void DeletePatron(long id)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
     {
         Patron toDelete = ctx.Patrons.Find(id);
         ctx.Patrons.Remove(toDelete);
         ctx.SaveChanges();
     }
 }
示例#46
0
        private static IQueryable<Item> Filter(LibraryDataContext ctx, IQueryable<Item> items, string filter)
        {
            if (String.IsNullOrWhiteSpace(filter))
                return items;

            return items.Where(item => item.Title.Contains(filter)
                                       ||
                                       item.ItemSubjects.Any(itemSubj => ctx.Lookups.FirstOrDefault(lookup => lookup.LookupName == "Subject" &&
                                                                                                              lookup.ID == itemSubj.LU_Subject).Value.Contains(filter))
                                       ||
                                       item.Authors.Any(author => (author.FirstName + " " + author.LastName + " " + author.Suffix).Contains(filter)));
        }
示例#47
0
        public static void Add(Lookup lookup)
        {
            using (LibraryDataContext ctx = new LibraryDataContext())
            {
                using (DbContextTransaction transaction = ctx.Database.BeginTransaction())
                {
                    int nextID = ctx.Lookups.Where(l => l.LookupName == lookup.LookupName).Max(l => l.ID) + 1;
                    lookup.ID = nextID;

                    ctx.Lookups.Add(lookup);
                    ctx.SaveChanges();
                }
            }
        }
示例#48
0
        public static Item GetItem(long id)
        {
            using (LibraryDataContext ctx = new LibraryDataContext())
            {
                Item found = ctx.Items.Find(id);
                ctx.Entry(found).Collection(item => item.Authors).Load();
                ctx.Entry(found).Collection(item => item.Editions).Load();
                foreach (Edition ed in found.Editions)
                    ctx.Entry(ed).Collection(edi => edi.Copies).Load();
                ctx.Entry(found).Collection(item => item.ItemSubjects).Load();
                ctx.Entry(found).Collection(item => item.Reserves).Load();

                return found;
            }
        }
示例#49
0
 public static IEnumerable<Item> GetAllItems(string filter, int pageSize, int pageNum)
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
         return Page(Filter(ctx, AllItems(ctx), filter).OrderBy(item => item.Title),
             pageSize, pageNum).ToList();
 }
示例#50
0
 public static IEnumerable<Patron> GetAllPatrons()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
         return ctx.Patrons.ToList();
 }
示例#51
0
 public static IEnumerable<MediaType> GetAllMediaTypes()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
         return ctx.MediaTypes.ToList();
 }
示例#52
0
 public static object GetAuthorByID(long id)
 {
     using (Data.LibraryDataContext ctx = new LibraryDataContext())
         return ctx.Authors.Find(id);
 }
示例#53
0
 public static IEnumerable<Publisher> GetAllPublishers()
 {
     using (LibraryDataContext ctx = new LibraryDataContext())
         return ctx.Publishers.ToList();
 }