//almost certainly not right! too heavy public static IEnumerable <Item> GetAllItems() { using (LibraryDataContext ctx = new LibraryDataContext()) { return(AllItems(ctx).OrderBy(item => item.Title).ToList()); } }
static public IEnumerable <Event> GetEvents() { using (var context = new LibraryDataContext()) { return(context.Events.ToList()); } }
static public int GetAllEventsNumber() { using (var context = new LibraryDataContext()) { return(context.Events.Count()); } }
public static void Initialize(LibraryDataContext db) { db.Books.AddRange( GetSeedingBooks() ); db.SaveChanges(); }
//almost certainly not right! too heavy public static IEnumerable<Item> GetAllItems() { using (LibraryDataContext ctx = new LibraryDataContext()) { return AllItems(ctx).OrderBy(item => item.Title).ToList(); } }
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); } }
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; }
public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILogger <BooksController> logger) { _context = context; _mapper = mapper; _config = config; _logger = logger; }
public IEnumerable <Reader> GetReaders() { using (var context = new LibraryDataContext()) { return(context.Readers.ToList()); } }
static public IEnumerable <Book> GetBooksByGenre(string g) { using (var context = new LibraryDataContext()) { return(context.Books.Where(book => book.genre.Equals(g)).ToList()); } }
public static void ReinitializeDb(LibraryDataContext db) { db.Books.RemoveRange(db.Books); // delete all the books. var x = db.SaveChangesAsync().Result; Initialize(db); }
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); }
public BooksController( LibraryDataContext context, IMapBooks mapper) { Context = context; Mapper = mapper; }
protected void CreateDatabaseIfNotExists() { using (var dataContext = new LibraryDataContext(_connectionString)) { dataContext.Database.CreateIfNotExists(); } }
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); }
public ReservationsController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILogReservations reservationLogger) { _context = context; _mapper = mapper; _config = config; _reservationLogger = reservationLogger; }
public static IEnumerable<Lookup> GetAllLookups() { using (LibraryDataContext ctx = new LibraryDataContext()) { return ctx.Lookups.ToList(); } }
public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration config, ILookupBooks bookLookup, IBookCommands bookCommands) { _context = context; _mapper = mapper; _config = config; _bookLookup = bookLookup; _bookCommands = bookCommands; }
public static void AddAuthor(Data.Author author) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) { ctx.Authors.Add(author); ctx.SaveChanges(); } }
public BooksController(LibraryDataContext context, IMapper mapper, MapperConfiguration mapperConfig, IQueryForBooks booksQuery, IDoBookCommands bookCommands) { _context = context; _mapper = mapper; _mapperConfig = mapperConfig; _booksQuery = booksQuery; _bookCommands = bookCommands; }
public static void AddPatron(Patron patron) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Patrons.Add(patron); ctx.SaveChanges(); } }
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)); }
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); }
private LibraryDataContext GetDataContext() { var dataContext = new LibraryDataContext(_connectionString); dataContext.Database.CreateIfNotExists(); return(dataContext); }
public static void AddPublisher(Publisher publisher) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Publishers.Add(publisher); ctx.SaveChanges(); } }
public void SelectBookWhichNotExistsFromDatabase() { using (var db = new LibraryDataContext()) { Book book = db.Books.FirstOrDefault(b => b.title.Equals("Harry -------- Potter")); Assert.IsNull(book); } }
public IEnumerable <Book> GetAllBooks() { using (var context = new LibraryDataContext()) //inside using it gets closed automatically { var result = context.Books.ToList(); return(result); } }
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(); } }
public static void DeletePatron(long id) { using (LibraryDataContext ctx = new LibraryDataContext()) { Patron toDelete = ctx.Patrons.Find(id); ctx.Patrons.Remove(toDelete); ctx.SaveChanges(); } }
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(); } }
public static void DeleteAuthor(long id) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) { Author a = ctx.Authors.Find(id); ctx.Authors.Remove(a); ctx.SaveChanges(); } }
public static void DeletePublisher(long publisherID) { using (LibraryDataContext ctx = new LibraryDataContext()) { Publisher publisher = ctx.Publishers.Find(publisherID); ctx.Publishers.Remove(publisher); ctx.SaveChanges(); } }
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(); } }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); DataContext = new LibraryDataContext(); InitializeCurrentUser(controllerContext.Request); InitializeCurrentVisitor(controllerContext.Request); }
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(); } }
public DashboardController(LibraryDataContext context) { appDbContext = context; serializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }; }
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))); }
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(); } } }
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; } }
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(); }
public static IEnumerable<Patron> GetAllPatrons() { using (LibraryDataContext ctx = new LibraryDataContext()) return ctx.Patrons.ToList(); }
public static IEnumerable<MediaType> GetAllMediaTypes() { using (LibraryDataContext ctx = new LibraryDataContext()) return ctx.MediaTypes.ToList(); }
public static object GetAuthorByID(long id) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) return ctx.Authors.Find(id); }
public static IEnumerable<Publisher> GetAllPublishers() { using (LibraryDataContext ctx = new LibraryDataContext()) return ctx.Publishers.ToList(); }