protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LibraryUI.Models.Book model = new LibraryUI.Models.Book(); string response = Utilities.Utilities.GetAPICall(Utilities.Utilities.GetAPIPath() + Utilities.Utilities.APIPath.FetchAllBook); if (response != null) { JsonResponse responseData = JsonConvert.DeserializeObject <JsonResponse>(response); List <LibraryUI.Models.Book> data = JsonConvert.DeserializeObject <List <LibraryUI.Models.Book> >(responseData.Data.ToString()); DataSet ds = Utilities.Utilities.ToDataSet <LibraryUI.Models.Book>(data); GridView1.DataSource = ds; GridView1.DataBind(); if (Session["RoleID"] != null) { if (Convert.ToInt32(Session["RoleID"].ToString()) != 1) { Add_new.Visible = false; //Button3.Visible = false; GridView1.Columns[0].Visible = false; } } } } }
protected void btn_save_Click(object sender, EventArgs e) { JsonResponse jsonResponse = new JsonResponse(); LibraryUI.Models.Book model = new LibraryUI.Models.Book(); if (txt_name.Text != "" && txt_author_name.Text != "" && txt_publisher.Text != "" && txt_price.Text != "" && txt_count.Text != "" && ddl_category.Text != "") { model.ID = Convert.ToInt64(hidden_id.Text); model.Name = txt_name.Text.ToString(); model.Aauthor = txt_author_name.Text.ToString(); model.Publisher = txt_publisher.Text.ToString(); model.Price = Convert.ToInt32(txt_price.Text.ToString()); model.Count = Convert.ToInt32(txt_count.Text.ToString()); model.Category = Convert.ToInt32(ddl_category.Text.ToString()); string response = string.Empty; if (model.ID != 0) { response = Utilities.PostAPICallWithParam <LibraryUI.Models.Book> .APICall(model, Utilities.Utilities.GetAPIPath() + Utilities.Utilities.APIPath.UpdateBook); } else { response = Utilities.PostAPICallWithParam <LibraryUI.Models.Book> .APICall(model, Utilities.Utilities.GetAPIPath() + Utilities.Utilities.APIPath.AddBook); } jsonResponse = JsonConvert.DeserializeObject <JsonResponse>(response); if (jsonResponse.Status == "S") { Server.Transfer("BookSummary.aspx"); } } else { if (txt_name.Text == "") { err_name.Text = "Please Enter Name"; } if (txt_author_name.Text == "") { err_author_name.Text = "Please Enter Author Name"; } if (txt_publisher.Text == "") { err_publisher.Text = "Please Enter Publisher"; } if (txt_price.Text == "") { err_price.Text = "Please Enter Price"; } if (txt_count.Text == "") { err_count.Text = "Please Enter Count"; } if (ddl_category.Text == "-1") { err_category.Text = "Please Enter Category"; } } }
public void Edit_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; int ID = Convert.ToInt32(row.Cells[1].Text); LibraryUI.Models.Book model = new LibraryUI.Models.Book(); string url; url = "Book.aspx?ID=" + ID; Response.Redirect(url); }
public List <LibraryUI.Models.Book> FetchData(long ID) { LibraryUI.Models.Book model = new LibraryUI.Models.Book(); List <LibraryUI.Models.Book> data = new List <Models.Book>(); string response = Utilities.Utilities.GetAPICall(Utilities.Utilities.GetAPIPath() + Utilities.Utilities.APIPath.FetchBookByID + "?ID=" + ID); if (response != null) { JsonResponse responseData = JsonConvert.DeserializeObject <JsonResponse>(response); data = JsonConvert.DeserializeObject <List <LibraryUI.Models.Book> >(responseData.Data.ToString()); } return(data); }
public void Delete_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; int ID = Convert.ToInt32(row.Cells[1].Text); LibraryUI.Models.Book model = new LibraryUI.Models.Book(); string response = Utilities.Utilities.GetAPICall(Utilities.Utilities.GetAPIPath() + Utilities.Utilities.APIPath.DeleteBook + "?ID=" + ID); if (response != null) { JsonResponse responseData = JsonConvert.DeserializeObject <JsonResponse>(response); Response.Redirect("BookSummary.aspx"); } }
public void AddBook(Book book) { // Find book in library int idx = _libraryBooks.FindIndex(b => b.Id == book.Id); // If found, add to counters if (idx >= 0) { _libraryBooks[idx].Copies += book.Copies; _libraryBooks[idx].Available += book.Copies; } else { // Add the copies to the library book.OnLoan = 0; book.Available = book.Copies; _libraryBooks.Add(book); } }
public void ReturnBook(Book book) { throw new NotImplementedException(); }
public void LoadData() { Book bk1 = new Book() { Id = 1, Title = "The furst book", Author="Someone", Copies=2, Available=1, OnLoan=1 }; Book bk2 = new Book() { Id = 2, Title = "The Second book", Author = "Someone Else", Copies = 1, Available = 1, OnLoan = 0 }; Book bk3 = new Book() { Id = 3, Title = "The Third book", Author = "Someone", Copies = 3, Available = 2, OnLoan = 1 }; _libraryBooks.Add(bk1); _libraryBooks.Add(bk2); _libraryBooks.Add(bk3); }
public void BorrowBook(Book book) { throw new NotImplementedException(); }