public ResponseObject Delete(decimal bookId) { try { BookObject obj = GetById(bookId); var rt = new ResponseObject(); if (obj == null) { return(new ResponseObject() { Code = 404, Message = "Livro não encontrado para deletar" }); } else { rt = _bookRepo.Delete(obj); } return(rt); } catch (Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
public async Task <IActionResult> Edit([Bind("Id,Name,Name,ShortDescription,Genre,Qty,QtyRented")] BookObject obj) { try { if (ModelState.IsValid) { if (obj.QtyRented > obj.Qty) { ViewBag.Error = "Quantidade alugada não pode ser maior do que a quantidade disponível em stoque"; return(View()); } var rt = _service.UpdateBookData(obj); if (rt.Code != 0) { ViewBag.Error = rt.Message; return(View()); } } else { ViewBag.Error = "Ocorreu um erro, favor verifique todos os campos se estão de acordo com o padrão"; return(View()); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ViewBag.Error = $"Erro: {ex.Message}"; return(View()); } }
public DefaultMethodResultObject UpdateBook(BookObject bookObject) { DefaultMethodResultObject result = new DefaultMethodResultObject(); try { using (var db = _context) { var foundBook = db.Books.SingleOrDefault(b => b.IdBook == bookObject.IdBook); if (foundBook != null) { foundBook.BookName = bookObject.BookName; foundBook.BookAuthor = bookObject.BookAuthor; foundBook.BookPublisher = bookObject.BookPublisher; foundBook.BookRegion = bookObject.BookRegion; foundBook.BookReleaseDate = bookObject.BookReleaseDate; db.Books.Update(foundBook); db.SaveChanges(); result.Code = 0; result.Message = "OK"; } } } catch (Exception ex) { result.Code = 999; result.Message = ex.Message; } return(result); }
public ResponseObject InsertBook(BookObject obj) { try { var alreadExists = _context.Book.Where(p => p.Name == obj.Name).Count() > 0; if (alreadExists) { return(new ResponseObject() { Code = 500, Message = "Este Livro já existe" }); } _context.Book.Add(obj); _context.SaveChanges(); return(new ResponseObject() { Code = 0, Message = "OK" }); } catch (Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
public IActionResult Create([Bind("Name,Name,ShortDescription,Genre,Qty,QtyRented")] BookObject book) { try { if (!ModelState.IsValid) { ViewBag.Error = "Por favor verifique os campos"; return(View()); } if (book.QtyRented > book.Qty) { ViewBag.Error = "Quantidade alugada não pode ser maior do que a quantidade disponível em stoque"; return(View()); } var rt = _service.InsertBook(book); if (rt.Code != 0) { ViewBag.Error = rt.Message; return(View()); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ViewBag.Error = $"Erro: {ex.Message}"; return(View()); } }
public ResponseObject UpdateBookData(BookObject obj) { try { BookObject bookToUpdate = _context.Book.Where( p => p.Id == obj.Id).FirstOrDefault(); if (bookToUpdate == null) { return(new ResponseObject() { Code = 404, Message = "Livro não encontrado" }); } bookToUpdate.Name = obj.Name; bookToUpdate.Qty = obj.Qty; bookToUpdate.QtyRented = obj.QtyRented; bookToUpdate.RentalPrice = obj.RentalPrice; bookToUpdate.ShortDescription = obj.ShortDescription; bookToUpdate.Genre = obj.Genre; _context.SaveChanges(); return(new ResponseObject() { Code = 0, Message = "OK" }); } catch (Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
/// <summary> /// load image and text of book in center of shelf. /// </summary> /// <param name="bo">BookObject</param> public void LoadImageandText(BookObject bo) { // change center text with title Title.GetComponent <Text>().text = bo.book.title; //change center image with character Image.GetComponent <Image>().sprite = Resources.Load <Sprite>(bo.book.pathToThumbnail); }
public DefaultMethodResultObject DeleteBookById(int id) { DefaultMethodResultObject result = new DefaultMethodResultObject(); try { using (var db = _context) { BookObject book = new BookObject() { IdBook = id }; _context.Books.Attach(book); _context.Books.Remove(book); _context.SaveChanges(); result.Code = 0; result.Message = "OK"; } } catch (Exception ex) { result.Code = 999; result.Message = ex.Message; } return(result); }
private void initLibrary() { string path = @"Database\MaterialItems.txt"; string[] materialData; materialData = File.ReadAllLines(path); foreach (string data in materialData) { string[] datas = data.Split('|'); string name = datas[1]; string author = datas[2]; string publisher = datas[3]; DateTime publishDate = Convert.ToDateTime(datas[4]); int stock = 0; bool isFile = false; if (datas[5] == "F") { isFile = true; stock = 0; } else { stock = Convert.ToInt16(datas[5]); } string type = datas[6]; switch (datas[0]) { case "Book": BookObject newBook = new BookObject(name, author, publisher, publishDate, stock); BookObserver newBookObserver = new BookObserver(newBook); this.materialList.Add(newBookObserver); break; case "EBook": EBookObject newEBook = new EBookObject(name, author, publisher, publishDate); EBookObserver newEBookObserver = new EBookObserver(newEBook); this.materialList.Add(newEBookObserver); break; case "Video": VideoObject newVideo = new VideoObject(name, type, author, publishDate, publisher, isFile, stock); VideoObserver newVideoObserver = new VideoObserver(newVideo); this.materialList.Add(newVideoObserver); break; case "Audio": AudioObject newAudio = new AudioObject(name, type, author, publishDate, publisher, isFile, stock); AudioObserver newAudioObserver = new AudioObserver(newAudio); this.materialList.Add(newAudioObserver); break; default: break; } } return; }
public BookObject GetById(decimal bookId) { var call = _api.ApiV1BooksGetbyidAsync(Convert.ToDouble(bookId)); call.Wait(); BookObject resultObj = _mapper.Map <BookObject>(call.Result); return(resultObj); }
public DefaultMethodResultObject UpdateBook(BookObject bookObject) { var call = _api.UpdateBookAsync(bookObject.IdBook, bookObject.BookName, bookObject.BookAuthor, bookObject.BookPublisher, bookObject.BookRegion, bookObject.BookReleaseDate); call.Wait(); Domain.Models.DefaultMethodResultObject resultObj = _mapper.Map <Domain.Models.DefaultMethodResultObject>(call.Result); return(resultObj); }
public ResponseObject Delete(BookObject obj) { var call = _api.ApiV1BooksDeletebookAsync(Convert.ToDouble(obj.Id)); call.Wait(); ResponseObject resultObj = _mapper.Map <ResponseObject>(call.Result); return(resultObj); }
public ResponseObject UpdateBook([FromBody] BookObject obj) { try { return(_bookService.UpdateBookData(obj)); } catch (System.Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
public ResponseObject UpdateBookData(BookObject obj) { var call = _api.ApiV1BooksUpdatebookAsync(new HBooksAPI.BookObject() { Genre = obj.Genre, Id = (double)obj.Id, Name = obj.Name, Qty = obj.Qty, QtyRented = obj.QtyRented, RentalPrice = obj.QtyRented, ShortDescription = obj.ShortDescription }); call.Wait(); ResponseObject resultObj = _mapper.Map <ResponseObject>(call.Result); return(resultObj); }
public ResponseObject InsertBook(BookObject obj) { var id = Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmss")); var call = _api.ApiV1BooksInserbookAsync(new HBooksAPI.BookObject() { Genre = obj.Genre, Id = (double)id, Name = obj.Name, Qty = obj.Qty, QtyRented = obj.QtyRented, RentalPrice = obj.QtyRented, ShortDescription = obj.ShortDescription }); call.Wait(); ResponseObject resultObj = _mapper.Map <ResponseObject>(call.Result); return(resultObj); }
public ResponseObject Delete(BookObject obj) { try { _context.Book.Remove(obj); _context.SaveChanges(); return(new ResponseObject() { Code = 0, Message = "OK" }); } catch (Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
public ResponseObject UpdateBookData(BookObject obj) { try { if (_validationService.Validate(obj, out var errorResult)) { return(errorResult); } var rt = _bookRepo.UpdateBookData(obj); return(rt); } catch (Exception ex) { return(ResponseObject.CreateSpecificError(ex)); } }
public async Task <IActionResult> CreateOrEditSave([Bind("IdBook,BookName,BookAuthor,BookPublisher,BookRegion,BookReleaseDate")] BookObject libraryBook) { if (ModelState.IsValid) { if (libraryBook.IdBook == 0) { _libraryService.InsertBook(libraryBook); } else { _libraryService.UpdateBook(libraryBook); } //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(libraryBook)); }
// GET: Employee/Create public IActionResult CreateOrEdit(int id) { BookObject libraryBook = new BookObject(); if (id > 0) { libraryBook = _libraryService.GetBookById(id); } if (libraryBook.IdBook == 0) { return(View(new BookObject())); } else { return(View(libraryBook)); } }
void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e) { if (e.Error != null) { return; } var type = JObject.Parse(e.Result).SelectToken("type").ToString(); var id = JObject.Parse(e.Result).SelectToken("id").ToString(); postAnswer.Add("access_token", App.AccessToken); postAnswer.Add("id", id); switch (type) { case "hometown": hometown = JsonConvert.DeserializeObject <HometownObject>(e.Result); setHometown(); break; case "music": music = JsonConvert.DeserializeObject <MusicObject>(e.Result); setMusic(); break; case "book": book = JsonConvert.DeserializeObject <BookObject>(e.Result); setBook(); break; case "movie": movie = JsonConvert.DeserializeObject <MovieObject>(e.Result); setMovie(); break; case "photo": photo = JsonConvert.DeserializeObject <PhotoObject>(e.Result); setPhoto(); break; } }
public DefaultMethodResultObject InsertBook(BookObject bookObject) { DefaultMethodResultObject result = new DefaultMethodResultObject(); try { using (var db = _context) { _context.Books.Add(bookObject); _context.SaveChanges(); result.Code = 0; result.Message = "OK"; } } catch (Exception ex) { result.Code = 999; result.Message = ex.Message; } return(result); }
public async Task <IActionResult> Create( [Bind("BookId,Name,ISBN,Publisher,BookType,Language,Ration,Cost,Image,Count")] Book book) { if (!ModelState.IsValid) { return(View(book)); } var code = int.Parse(_context.BookObjects.Select(bo => bo.BookCode).Last()); for (var i = 0; i < book.Count; i++) { code++; var bo = new BookObject(); bo.BookCode = $"{code}"; bo.BookInfo = book; _context.Add(bo); } _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public DefaultMethodResultObject InsertBook(BookObject bookObject) { return(_libraryService.InsertBook(bookObject)); }
public BookObserver(BookObject subject) { this.bookContext = subject; }
public DefaultMethodResultObject UpdateBook(BookObject bookObject) { return(_libraryService.UpdateBook(bookObject)); }
// Parses the Json for the Book Info Box public string ParseBook(JObject bookJson) { BookObject book = new BookObject(); // Create the book object JObject volumeInfoObject = (JObject)bookJson["volumeInfo"]; // Reading book info for attributes JObject searchInfoObject = (JObject)bookJson["searchInfo"]; // Reading search info for blurb StringBuilder sb = new StringBuilder(); // Printing to screen bool[] resultBool = new bool[resultsListBox.Items.Count]; for (int i = 0; i <= resultsListBox.Items.Count - 1; i++) { resultBool[i] = resultsListBox.GetItemChecked(i); } if (resultBool[0]) { book.title = ParseString(volumeInfoObject, "title"); sb.Append("Title: " + book.title + " \r\n"); } if (resultBool[1]) { MatchCollection mc = Regex.Matches(bookJson["selfLink"].ToString(), "(?<=volumes/).*"); // Parsing ID foreach (Match m in mc) { book.id += m; } sb.Append("Volume ID: " + book.id + "\r\n"); } if (resultBool[2]) { //Console.WriteLine("Search info object: " + searchInfoObject.ToString()); book.blurb = ParseString(searchInfoObject, "textSnippet"); sb.Append("Blurb: " + book.blurb); } if (resultBool[3]) { book.publisher = ParseString(volumeInfoObject, "publisher"); sb.Append("Publisher: " + book.publisher + " \r\n"); } if (resultBool[4]) { book.publishedDate = ParseString(volumeInfoObject, "publishedDate"); sb.Append("Published: " + book.publishedDate + " \r\n"); } if (resultBool[5]) { book.pageCount = ParseInt(volumeInfoObject, "pageCount"); sb.Append("Page Count: " + book.pageCount + " \r\n"); } if (resultBool[6]) { JArray authors = (JArray)volumeInfoObject["authors"]; sb.Append("Authors: "); if (authors != null) { foreach (var author in authors) { book.authors.Add(author.ToString()); sb.Append(author + ", "); } } sb.Append("\r\n"); } if (resultBool[7]) { book.description = ParseString(volumeInfoObject, "description"); sb.Append(" \r\n"); sb.Append("Description: " + book.description + " \r\n"); } //// Parsing Availability // "PDF Available", "PDF Link", "Epub Available", "Epub Link", "For Sale", "Sale Link JObject countryObject = ParseJObject(bookJson, "country"); if (countryObject.Count == 0) { book.pdfAvailable = false; book.pdfLink = "N/A"; book.epubAvailable = false; book.epubLink = "N/A"; } else { JObject epubObject = (JObject)countryObject["epub"]; // Reading Epub JObject pdfObject = (JObject)countryObject["pdf"]; // Reading PDF book.pdfAvailable = ParseBool(pdfObject, "isAvailable"); book.pdfLink = ParseString(pdfObject, "acsTokenLink"); book.epubAvailable = ParseBool(epubObject, "isAvailable"); book.epubLink = ParseString(epubObject, "acsTokenLink"); } JObject saleInfoObject = ParseJObject(bookJson, "saleInfo"); // Reading sale if (saleInfoObject.Count == 0) { book.forSale = "Not for sale"; book.saleLink = "N/A"; } else { book.forSale = ParseString(saleInfoObject, "saleability"); book.saleLink = ParseString(saleInfoObject, "buyLink"); if (book.saleLink == "") { book.saleLink = "N/A"; } } // Retrieving the availability items and items checked bool[] availBool = new bool[availabilityListBox.Items.Count]; for (int i = 0; i <= availabilityListBox.Items.Count - 1; i++) { availBool[i] = availabilityListBox.GetItemChecked(i); } if (availBool[0]) { sb.Append("PDF Available: " + book.pdfAvailable + " \r\n"); } if (availBool[1]) { sb.Append("PDF Link: " + book.pdfLink + " \r\n"); } if (availBool[2]) { sb.Append("EPUB Available: " + book.epubAvailable + " \r\n"); } if (availBool[3]) { sb.Append("EPUB Link: " + book.epubLink + " \r\n"); } if (availBool[4]) { sb.Append("For Sale: " + book.forSale + " \r\n"); } if (availBool[5]) { sb.Append("Sale Link: " + book.saleLink + " \r\n"); } return(sb.ToString()); }
public static void Remove(this IRecipeBook recipeBook, BookObject domainObject) { recipeBook.Remove(domainObject.Id); }
private void button1_Click(object sender, EventArgs e) { bool errorCheck = Validation(); if (errorCheck) { return; } else { string classname = comboBox1.Items[comboBox1.SelectedIndex].ToString(); string name = textBox1.Text; string author = textBox2.Text; string publisher = textBox3.Text; DateTime publishDate = monthCalendar1.SelectionStart; int stock = 0; if (textBox5.Enabled) { stock = Int16.Parse(textBox5.Text); } string type = ""; if (textBox6.Enabled) { type = textBox6.Text; } bool isDigital = false; switch (classname) { case "Book": BookObject newBook = new BookObject(name, author, publisher, publishDate, stock); returnItem = new BookObserver(newBook); break; case "E-Book": EBookObject newEBook = new EBookObject(name, author, publisher, publishDate); returnItem = new EBookObserver(newEBook); break; case "Video (Physical)": case "Video (Digital)": if (classname.Contains("Digital")) { isDigital = true; } VideoObject newVideo = new VideoObject(name, type, author, publishDate, publisher, isDigital, stock); returnItem = new VideoObserver(newVideo); break; case "Audio (Physical)": case "Audio (Digital)": if (classname.Contains("Digital")) { isDigital = true; } AudioObject newAudio = new AudioObject(name, type, author, publishDate, publisher, isDigital, stock); returnItem = new AudioObserver(newAudio); break; default: break; } this.DialogResult = DialogResult.OK; this.Close(); return; } }