// POST api/songs public void Post([FromBody] Song song) { LibraryEntities context = new LibraryEntities(); context.Songs.Add(song); context.SaveChanges(); }
// GET: Book public ActionResult BookList() { LibraryEntities db = new LibraryEntities(); var books = from Aut in db.Authors join It in db.Items on Aut.AuthorID equals It.AuthorID select new ItemLibrarianViewModel { It = It, Aut = Aut }; /*foreach (ItemLibrarianViewModel i in books.ToList()) * { * Debug.WriteLine("YOOOOOOOOO"); * Copy cp = new Copy(); * for (int z = 0; z < 5; z++) * { * cp.Isbn = i.It.Isbn; * cp.Borrowed = "n"; * db.Copies.Add(cp); * } * db.SaveChanges(); * * }*/ books.ToList(); return(View(books)); }
public bool IsLoginNameExist(string loginName) { using (LibraryEntities db = new LibraryEntities()) { return(db.SYSUser.Where(x => x.LoginName.Equals(loginName)).Any()); } }
protected void Page_Load(object sender, EventArgs e) { LibraryEntities db = new LibraryEntities(); this.RepeaterMain.DataSource = db.Books.ToList(); this.RepeaterMain.DataBind(); }
private void buttonEnter_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); var clients = context.Clients; bool flag = false; foreach (var item in clients) { if (int.Parse(textBoxID.Text) == item.ClientID && textBoxEGN.Text.Trim() == item.EGN.Trim()) { flag = true; } } if (flag == true) { Menu menu = new Menu(int.Parse(textBoxID.Text)); menu.Show(); InitializeMyControl(); Clear(); } else { MessageBox.Show("Грешка! Невалидна парола!"); InitializeMyControl(); Clear(); } }
public ActionResult EditBook([Bind(Include = "Isbn,Name,Year,Subject,Type")] Item it) { using (LibraryEntities db = new LibraryEntities()) { if (ModelState.IsValid) { var book = from i in db.Items join a in db.Authors on i.AuthorID equals a.AuthorID where it.Isbn == i.Isbn && i.AuthorID == a.AuthorID select i; foreach (Item i in book.ToList()) { if (it.Isbn == i.Isbn) { i.Name = it.Name; i.Subject = it.Subject; i.Type = it.Type; } } try { db.SaveChanges(); TempData["editMessage"] = "Book Records Updated."; return(RedirectToAction("BookList")); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } } return(View(it)); } }
public EmployeeDashboard(Form login, Employee e) { InitializeComponent(); _login = login; _db = new LibraryEntities(); employee = e; }
public ActionResult AdminArea(Librarian l) { using (LibraryEntities db = new LibraryEntities()) { // Add books. if (ModelState.IsValid) { db.Librarians.Add(l); try { db.SaveChanges(); if (l.LibrarianID > 0) { ViewBag.Success = l.Name.ToString(); } return(View()); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } ModelState.Clear(); } return(View()); } //end ModelStateif } //end ActionResult
private void buttonReserve_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); List<int> books = new List<int>(); foreach (DataGridViewRow row in dataGridViewBooks.SelectedRows) { if (row.Cells[0].Value != null) { books.Add(Convert.ToInt32(row.Cells[0].Value)); } } if (books.Count > 0) { var client = (from c in context.Clients where c.ClientID == id select c).SingleOrDefault(); foreach (LibraryReader.ClientsBook cBook in client.ClientsBooks) { if (books.Contains(cBook.BookID)) { cBook.Reservation = true; MessageBox.Show("Резервирането е успешно!"); } } context.SaveChanges(); } }
// POST api/artists public void Post([FromBody] Artist artist) { LibraryEntities context = new LibraryEntities(); context.Artists.Add(artist); context.SaveChanges(); }
public IEnumerable <Library_System.Models.Category> DropDownListCategoryEdit_GetData() { LibraryEntities db = new LibraryEntities(); var result = db.Categories.ToList(); return(result); }
public CreateOrder(EmployeeDashboard employee, Employee e) { InitializeComponent(); _employee = employee; employ = e; _db = new LibraryEntities(); }
public ReturnOrder(CreateOrder o) { InitializeComponent(); _db = new LibraryEntities(); _order = o; }
public AdminDashboard(Form login, User user) { InitializeComponent(); _login = login; _user = user; db = new LibraryEntities(); }
public List <Book> GetAll() { using (LibraryEntities db = new LibraryEntities()) { return(db.Book.ToList()); } }
public ActionResult UpdatePassword(string passwordHash) { using (var db = new LibraryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var activeAccount = (AccountAdapter)System.Web.HttpContext.Current.Session["activeAccount"]; Login userLogin = db.Logins.Where(x => x.AccountId == activeAccount.AccountNumber).SingleOrDefault(); userLogin.PasswordHash = passwordHash; userLogin.IsPasswordTemporary = false; db.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); return(new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError)); } } } return(RedirectToAction("Home")); }
public ActionResult AddStudent(ItemLibrarianViewModel libObj) { using (LibraryEntities db = new LibraryEntities()) { //Add students if (ModelState.IsValid) { Customer cust = new Customer(); cust.CustName = libObj.C.CustName; cust.CustEmail = libObj.C.CustEmail; cust.Field = libObj.C.Field; cust.Privalige = libObj.C.Privalige; cust.CPassword = libObj.C.CPassword; db.Customers.Add(cust); ModelState.Clear(); } try { db.SaveChanges(); TempData["addStudent"] = "Student Added: " + libObj.C.CustName; return(RedirectToAction("AddStudent")); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } } //end ModelStateif return(View()); } //end ActionResult
public ActionResult BookListSorted(string column) { LibraryEntities db = new LibraryEntities(); //LINQ Query if (column == "Title") { ViewBag.Books = (from b in db.books orderby b.Title select b).ToList(); } else if (column == "Author") { ViewBag.Books = (from b in db.books orderby b.Author select b).ToList(); } else if (column == "Status") { ViewBag.Books = (from b in db.books orderby b.Status select b).ToList(); } else if (column == "YearPublished") { ViewBag.Books = (from b in db.books orderby b.YearPublished select b).ToList(); } return(View("BookList")); }
protected void ButtonCreate_Click(object sender, EventArgs e) { string text = this.TextBoxCategoryCreate.Text; if (!string.IsNullOrWhiteSpace(text) && !string.IsNullOrEmpty(text) && text.Length < 150) { Category newCategiry = new Category(); newCategiry.CategoryName = text; LibraryEntities db = new LibraryEntities(); db.Categories.Add(newCategiry); try { db.SaveChanges(); Error_Handler_Control.ErrorSuccessNotifier.AddSuccessMessage("Category created!"); } catch (Exception ex) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage(ex.Message); return; } } else { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage( "Name mast be Max.150 chars and can not be null or empty string!"); } this.PanelCreate.Visible = false; Response.Redirect("EditCategories.aspx"); }
public AdminBorrowControl() { InitializeComponent(); try { using (var db = new LibraryEntities()) { var borrowController = (from bc in db.BorrowController join b in db.Books on bc.BookID equals b.BookID select new { Indeks = bc.Index, Tytul = bc.Books.Title, Autor = b.Authors.FirstName + b.Authors.LastName, Od = bc.From, Do = bc.To }); dataGridView1.DataSource = borrowController.ToList(); } } catch (Exception ex) { MessageBox.Show("Wystapil blad podczas laczenia z baza danych:\n\n" + ex); } }
// The return type can be changed to IEnumerable, however to support // paging and sorting, the following parameters must be added: // int maximumRows // int startRowIndex // out int totalRowCount // string sortByExpression public IQueryable <Category> GridViewCategories_GetData() { LibraryEntities db = new LibraryEntities(); var result = db.Categories; return(result); }
private void button1_Click(object sender, EventArgs e) { // Dodaj using (var db = new LibraryEntities()) { try { var newPublisher = new Publishers(); newPublisher.Name = textBox1.Text; newPublisher.City = textBox2.Text; newPublisher.Street = textBox3.Text; newPublisher.HouseNumber = textBox4.Text; newPublisher.ApartmentNumber = Convert.ToInt32(textBox5.Text); db.Publishers.Add(newPublisher); db.SaveChanges(); } catch (Exception exc) { MessageBox.Show("Wystapil blad podczas zapisywania danych w bazie:\n\n" + exc); return; } MessageBox.Show("Rekord pomyslnie zapisano!"); this.Hide(); } }
public void Handle(IStrategyContext context) { var book = context.Resolve <BookDto>(); using (var dbContext = new LibraryEntities()) { if (book.Id != Guid.Empty) { var entity = dbContext.Books .Where(x => x.Id == book.Id) .SingleOrDefault(); Mapper.Map(book, entity); context.Response = entity.Id; } else { var entity = Mapper.Map <Book>(book); entity.Id = Guid.NewGuid(); context.Response = entity.Id; dbContext.Books.Add(entity); } dbContext.SaveChanges(); } }
public Loan GetById(int id) { using (LibraryEntities db = new LibraryEntities()) { return(db.Loan.Find(id)); } }
public ActionResult ConfirmRequest(long Isbn, string name, string subject, string type, int year, string auth) { if (Session["libID"] != null) { using (LibraryEntities db = new LibraryEntities()) { var reqItem = from rIt in db.ReqStudents where rIt.Isbn == Isbn select rIt; if (ModelState.IsValid) { Item i = new Item(); Author a = new Author { AuthName = auth, Isbn = Isbn }; i.AuthorID = a.AuthorID; i.Isbn = Isbn; i.Name = name; i.Subject = subject; i.Type = type; i.Year = year; foreach (ReqStudent req in reqItem.ToList()) { req.ReqConfirmation = "Confirmed"; } db.Authors.Add(a); db.Items.Add(i); for (int index = 0; index < 10; index++) { Copy cp = new Copy(); cp.Isbn = Isbn; cp.Borrowed = "n"; db.Copies.Add(cp); } try { db.SaveChanges(); TempData["reqConfirm"] = "Book Added"; return(RedirectToAction("Requests")); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } } } return(RedirectToAction("Requests")); } else { return(RedirectToAction("StaffLogin")); } }
public IEnumerable <Book> SearchBook(string txtSearch, bool?availability) { using (LibraryEntities db = new LibraryEntities()) { txtSearch = txtSearch.ToLower(); if (availability != null) { var searchAvailable = from items in db.Book where (items.isAvailable == availability) && (items.Author.ToLower().Contains(txtSearch) || items.Title.ToLower().Contains(txtSearch) || items.ISBN.ToLower().Contains(txtSearch)) select items; return(searchAvailable.ToList()); } else { var search = from items in db.Book where items.Author.ToLower().Contains(txtSearch) || items.Title.ToLower().Contains(txtSearch) || items.ISBN.ToLower().Contains(txtSearch) select items; return(search.ToList()); } } }
public ActionResult CurrentlyLoaned() { if (Session["libID"] != null) { if (TempData["fine"] != null) { ViewBag.FineMessage = TempData["fine"].ToString(); } using (LibraryEntities db = new LibraryEntities()) { var loanQuery = from i in db.Items join c in db.Copies on i.Isbn equals c.Isbn join t in db.Transactions on c.CopyID equals t.CopyID join cS in db.Customers on t.CustID equals cS.CustID where i.Isbn == c.Isbn && c.CopyID == t.CopyID && t.TransacType != "Returned" && t.CustID == cS.CustID && c.Borrow_Date != null select new ItemLibrarianViewModel { It = i, Cp = c, Tc = t, C = cS }; /*foreach (ItemLibrarianViewModel item in loanQuery.ToList()) * { * }*/ return(View(loanQuery.ToList())); } } else { return(RedirectToAction("StaffLogin")); } }
public Book GetById(int?id) { using (LibraryEntities db = new LibraryEntities()) { return(db.Book.Find(id)); } }
public ActionResult BookReturned(int bookId) { using (LibraryEntities db = new LibraryEntities()) { if (ModelState.IsValid) { /*UPDATE DATA MODEL SO TRANSACTION HOLDS BORROW AND RETURN FIELDS COPY ONLY FOR COPY ID ISBN AND Y/N BORRED OR NOT*/ int cuID = Int32.Parse(Session["custID"].ToString()); var returnQuery = from c in db.Copies join t in db.Transactions on c.CopyID equals t.CopyID where c.CopyID == t.CopyID && c.Isbn == bookId && t.CustID == cuID select c; foreach (Copy cp in returnQuery.ToList()) { cp.Borrow_Date = null; cp.Return_Date = null; cp.Borrowed = "n"; db.SaveChanges(); if (cp.Borrowed == "n") { TempData["returnMessage"] = "Book Returned"; return(RedirectToAction("UserArea")); } } } //end model state if ModelState.Clear(); } return(RedirectToAction("UserArea")); }
public ActionResult NewTemporaryPassword(string user) { using (var db = new LibraryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { Login targetLogin = db.Logins.Where(x => x.Username == user).SingleOrDefault(); if (targetLogin == null) { return(notification.ResetPasswordUserNotFound()); } var newTempPassword = GenerateTemporaryPassword(); targetLogin.PasswordHash = HashString(newTempPassword); targetLogin.IsPasswordTemporary = true; db.SaveChanges(); transaction.Commit(); return(notification.ResetPasswordSuccess(newTempPassword)); } catch { transaction.Rollback(); return(notification.UnknownError()); } } } }
protected void ButtonConfirmDelete_Click(object sender, EventArgs e) { if (BookId < 1) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage( "Wrong Category Id!"); } else { LibraryEntities db = new LibraryEntities(); Book book = db.Books.Find(BookId); try { db.Books.Remove(book); db.SaveChanges(); Error_Handler_Control.ErrorSuccessNotifier.AddSuccessMessage( "Book Removed!"); } catch (Exception ex) { Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage(ex.Message); return; } } this.PanelDelete.Visible = false; this.BookId = 0; Response.Redirect("EditBooks.aspx"); }
public static async Task<List<Author>> GetAllAuthors() { using (LibraryEntities entities = new LibraryEntities()) { var authors = from autor in entities.Authors select autor; return await authors.ToListAsync(); } }
public static async Task<List<Book>> GetByCategory(Category category) { using (LibraryEntities entities = new LibraryEntities()) { entities.Configuration.LazyLoadingEnabled = true; var books = entities.Books.Include("Author").Include("Category").Where(x => x.Category.id == category.id); return await books.ToListAsync(); } }
public static async Task<List<Book>> GetAllBooks() { using (LibraryEntities entities = new LibraryEntities()) { entities.Configuration.LazyLoadingEnabled = true; var books = from book in entities.Books.Include("Author").Include("Category") select book; return await books.ToListAsync(); } }