// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapGet("/", async context => { BookGrpcClient service = context.RequestServices.GetService <BookGrpcClient>(); CreateBookResult r = null; try { r = service.CreateBook(new CreateBookCommand { BuyerId = "abc" }); } catch (Exception ex) { } await context.Response.WriteAsync(r.Id.ToString()); }); }); }
public IActionResult Create(CreateBook model) { if (ModelState.IsValid) { var result = new CreateBookResult(); result = Helper.ApiHelper <CreateBookResult> .HttpPostAsync("api/Book/create", "POST", model); if (result.BookId > 0) { return(RedirectToAction("index")); } ModelState.AddModelError("", result.Message); return(View(model)); } return(View(model)); }
public List<CreateBookResult> searchBookResult(int indexpage, SearchBook bookData) { List<CreateBookResult> returnValue = new List<CreateBookResult>(); DataBase Base = new DataBase(); string ConditionReturn = this.SearchBookConditionReturn(bookData, "BookDatabase"); using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString())) { try { StaffDataBase sDB = new StaffDataBase(); List<string> CreateFileName = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name); Sqlconn.Open(); string sql = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY BookDatabase.BookID DESC) " + "AS RowNum, BookDatabase.*, BookCategory.CategoryCode, BookCategory.CategoryName FROM BookDatabase " + "RIGHT JOIN BookCategory ON BookDatabase.CategoryID=BookCategory.ID " + "WHERE BookDatabase.isDeleted=0 " + ConditionReturn + " ) " + "AS NewTable " + "WHERE RowNum >= (@indexpage-" + PageMinNumFunction() + ") AND RowNum <= (@indexpage)"; SqlCommand cmd = new SqlCommand(sql, Sqlconn); cmd.Parameters.Add("@indexpage", SqlDbType.Int).Value = indexpage; cmd.Parameters.Add("@txtbookNumber", SqlDbType.NVarChar).Value = Chk.CheckStringFunction(bookData.txtbookNumber); cmd.Parameters.Add("@txtbookTitle", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(bookData.txtbookTitle) + "%"; cmd.Parameters.Add("@txtbookClassification", SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(bookData.txtbookClassification); cmd.Parameters.Add("@txtbookAuthor", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(bookData.txtbookAuthor) + "%"; cmd.Parameters.Add("@txtbookPress", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(bookData.txtbookPress) + "%"; SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { CreateBookResult addValue = new CreateBookResult(); addValue.bID = dr["BookID"].ToString(); addValue.bookNumber = dr["BookCodeID"].ToString(); addValue.bookTitle = dr["BookName"].ToString(); addValue.bookClassificationCode = dr["CategoryCode"].ToString(); addValue.bookClassificationName = dr["CategoryName"].ToString(); addValue.bookAuthor = dr["Author"].ToString(); addValue.bookPress = dr["Press"].ToString(); addValue.checkNo = "1"; returnValue.Add(addValue); } dr.Close(); Sqlconn.Close(); } catch (Exception e) { CreateBookResult addValue = new CreateBookResult(); addValue.checkNo = "-1"; addValue.errorMsg = e.Message.ToString(); returnValue.Add(addValue); } } return returnValue; }