// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(routeBuilder => { routeBuilder.MapODataServiceRoute("ODataRoutes", "odata", //OData routing, should match launchUrl in launchSettings.json BookModelBuilder.GetEdmModel(app.ApplicationServices)); routeBuilder.EnableDependencyInjection(); }); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; //serve the swagger UI at the app's root }); }
public ActionResult Return(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } var model = new BookViewModel(); var bookBuilder = new BookModelBuilder(); var modelList = bookBuilder.CreateModelList(b => b.ISBN.StartsWith(id), 0, 1); if (modelList.Any()) { model = modelList.FirstOrDefault(); var userName = User.Identity.Name; var userBuilder = new LibraryUserModelBuilder(); var userModel = userBuilder.BuildModelFrom(userName); ViewBag.IsBookRentByMe = userModel.RentBooks != null && userModel.RentBooks.Where(r => r.ISBN.CompareTo(model.ISBN) == 0).Any(); } else { return(RedirectToAction("Index")); } return(View(model)); }
// GET: Book public ActionResult Index() { var bookBuilder = new BookModelBuilder(); var model = bookBuilder.CreateModelList(b => !string.IsNullOrEmpty(b.BookName), 0, 20); return(View(model)); }
public bool CheckISBNExisted(string ISBN) { bool result = false; if (!string.IsNullOrEmpty(ISBN)) { var bookBuilder = new BookModelBuilder(); var books = bookBuilder.CreateModelList(b => b.ISBN.CompareTo(ISBN) == 0, 0, 1); result = books.Any(); } return(result); }
public async Task <ActionResult> Cover(string id) { var model = new BookViewModel(); var bookBuilder = new BookModelBuilder(); var modelList = await bookBuilder.CreateModelListAsync(b => b.ISBN.StartsWith(id), 0, 1); if (modelList.Any()) { model = modelList.FirstOrDefault(); return(File(model.Cover, "image/jpg")); } else { return(new HttpNotFoundResult()); } }
public ActionResult Rent(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } var model = new BookViewModel(); var bookBuilder = new BookModelBuilder(); var modelList = bookBuilder.CreateModelList(b => b.ISBN.StartsWith(id), 0, 1); if (modelList.Any()) { model = modelList.FirstOrDefault(); } else { return(RedirectToAction("Index")); } return(View(model)); }