public IEnumerable <BookStoreModel> GetBooks() { List <BookStoreModel> bookList = new List <BookStoreModel>(); using (SqlConnection con = new SqlConnection(configuration["ConnectionStrings:UserDbConnection"])) { SqlCommand cmd = new SqlCommand("GETBOOK", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { BookStoreModel bookStore = new BookStoreModel(); bookStore.BookID = Convert.ToInt32(rdr["BookID"]); bookStore.BookTittle = rdr["BookTittle"].ToString(); bookStore.AuthorName = rdr["AuthorName"].ToString(); bookStore.Price = Convert.ToInt32(rdr["Price"]); bookStore.BookImage = rdr["BookImage"].ToString(); bookStore.Summary = rdr["Summary"].ToString(); bookStore.BookCount = Convert.ToInt32(rdr["BookCount"]); bookList.Add(bookStore); } con.Close(); } return(bookList); }
public Task <int> AddBooksDetail(BookStoreModel bookStoreModel) { userDBContext.BookStore.Add(bookStoreModel); var result = userDBContext.SaveChangesAsync(); return(result); }
public int GetBookCustomers(int bookId) { using (BookStoreModel db = new BookStoreModel()) { return(db.Books.Where(x => x.ID == bookId).Include(p => p.Customers).First().Customers.Count); } }
public void insert(BookStoreModel bookStore) { string sqlQuery = @"insert into book_stores (storeName, cashBalance, openingHours) values (@storeName, @cashBalance, @openingHours);"; using (var cn = new SQLiteConnection(connectionString)) { cn.Execute(sqlQuery, bookStore); } }
public ActionResult BooksReport() { using (BookStoreModel db = new BookStoreModel()) { var booksList = (from book in db.Books group book by book.Genre into g select g).ToList(); return(View(booksList)); } }
public async Task <IActionResult> AddBookDetails(BookStoreModel bookStoreModel) { var result = await this.bookManager.AddBooksDetail(bookStoreModel); if (result == 1) { return(this.Ok(bookStoreModel)); } else { return(this.BadRequest()); } }
public void WhenCallImportWithEmptyCatalogAsJson_ReturnsBadRequestErrorMessageResult() { _bookStoreService.Setup(m => m.ImportStock(CATALOGASJSON)).Returns("import successfully"); BookStoreController controller = new BookStoreController(_bookStoreService.Object); BookStoreModel model = new BookStoreModel(); model.CatalogAsJson = string.Empty; var result = controller.Import(model); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), result); }
public void WhenCallInsertWithCorrectJsonSchema_ReturnsOkResult() { _bookStoreService.Setup(m => m.ImportStock(CATALOGASJSON)).Returns("import successfully"); BookStoreController controller = new BookStoreController(_bookStoreService.Object); BookStoreModel model = new BookStoreModel(); model.CatalogAsJson = CATALOGASJSON; var result = controller.Import(model); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <string>), result); }
public void TestAddBook() { Mock <ModelOperation> mock = new Mock <ModelOperation>(); BookStoreModel bookStoreModel = new BookStoreModel(); //BookStore store = new BookStore(); mock.Setup(m => m.AddBooks(bookStoreModel)).Returns(1); var controller = new BookStoreController(mock.Object); IHttpActionResult http = controller.Post(bookStoreModel); var actual = http as OkNegotiatedContentResult <string>; Assert.AreEqual("Success inserted book", actual.Content); }
public IHttpActionResult Getbookcon(int id) { BookStoreModel model = null; model = modelOperation.GetBookById(id); if (model != null) { return(Ok(model)); } else { return(NotFound()); } }
public int AddBooks(BookStoreModel storeModel) { using (SqlConnection con = new SqlConnection(configuration["ConnectionStrings:UserDbConnection"])) { SqlCommand cmd = new SqlCommand("AddBooks", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BookTittle", storeModel.BookTittle); cmd.Parameters.AddWithValue("@AuthorName", storeModel.AuthorName); cmd.Parameters.AddWithValue("@Price", storeModel.Price); cmd.Parameters.AddWithValue("@Summary", storeModel.Summary); cmd.Parameters.AddWithValue("@BookImage", storeModel.BookImage); cmd.Parameters.AddWithValue("@BookCount", storeModel.BookCount); con.Open(); int row = cmd.ExecuteNonQuery(); con.Close(); return(row); } }
public IHttpActionResult Post([FromBody] BookStoreModel bookModel) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } int res = modelOperation.AddBooks(bookModel); if (res != 0) { return(Ok("Success inserted book")); } else { return(BadRequest("Not Inserted")); } }
public IHttpActionResult PutIntoFavList(int id, [FromBody] BookStoreModel bookModel) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } int res = modelOperation.PutIntoFavList(id, bookModel); if (res != 0) { return(Ok()); } else { return(NotFound()); } }
public IHttpActionResult Import([FromBody] BookStoreModel model) { string catalogAsJson = model.CatalogAsJson; if (string.IsNullOrEmpty(catalogAsJson)) { return(BadRequest("Not provided catalog json")); } JSchema jsonSchema = JSchema.Parse(Constants.JSON_SCHEMA); JObject jsonObject = JObject.Parse(catalogAsJson); if (!jsonObject.IsValid(jsonSchema)) { return(BadRequest("Invalid data")); } else { return(Ok(_bookStoreService.ImportStock(catalogAsJson))); } }
public ActionResult AddBooks(BookStoreModel storeModel) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:61245/api/"); //HTTP POST var postTask = client.PostAsJsonAsync <BookStoreModel>("BookStore", storeModel); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Details")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(storeModel)); }
public IActionResult AddBooks(BookStoreModel bookStoreModel) { var result = bookManager.AddBooks(bookStoreModel); try { if (result == 1) { this.distributedCache.Remove(key); msmq.SendMessage("Books name " + bookStoreModel.BookTittle + " added successfully.", result); return(this.Ok(bookStoreModel)); } else { return(this.BadRequest(JsonErrorModel.Json())); } } catch (BookStoreException) { return(BadRequest(Exception_type.Invalid_exception.ToString())); } }
public ActionResult AddFavBook(int id) { BookStoreModel books = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:61245/api/"); var responseTask = client.GetAsync("BookStore?id=" + id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <BookStoreModel>(); readTask.Wait(); books = readTask.Result; } } return(RedirectToAction("FavList")); }
public DanhSachController() { context = DataProvider.Entities; }
public bookInfoController(BookStoreModel db) { this.db = db; }
public Task <int> AddBooksDetail(BookStoreModel bookStoreModel) { return(this.bookRepository.AddBooksDetail(bookStoreModel)); }
public void add_book_store([FromBody] BookStoreModel bookStore) { BookStoreDAO bookStoreDAO = new BookStoreDAO(); bookStoreDAO.insert(bookStore); }
public bookLocationsController(BookStoreModel db) { this.db = db; }
static StoreService() { BookStore = new BookStoreModel(); }
/// <summary> /// Adds the books detail. /// </summary> /// <param name="bookStoreModel">The book store model.</param> /// <returns></returns> public int AddBooks(BookStoreModel bookStoreModel) { return(bookRepository.AddBooks(bookStoreModel)); }