public async Task <ActionResult> SearchCars1(FormCollection data) { Dictionary <string, string> form = data.AllKeys.ToDictionary(k => k, v => data[v]); var qry = "PowerFrom=" + data["PowerFrom"] + "&PowerTo=" + data["PowerTo"] + "&FromMil=" + data["FromMil"] + "&ToMil=" + data["ToMil"]; AutosVehicle autosVehicle = new AutosVehicle(); var myContent = JsonConvert.SerializeObject(form); try { var data1 = new StringContent(qry + myContent, Encoding.UTF8, "application/json"); var url = "https://localhost:44363/api/AutosVehicles/SearchCars"; var client = new HttpClient(); var response = await client.PostAsync(url, data1); var AutosSearch = response.Content.ReadAsStringAsync().Result; AutosVehicle[] a = JsonConvert.DeserializeObject <AutosVehicle[]>(AutosSearch); ViewBag.AutosVehicle = a; return(ViewBag.AutosVehicle = a); } catch (Exception) { Error err = new Error(); err.ErrorMessage = "Sorry we found no cars with these filters"; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } }
public async Task <ActionResult <AutosVehicle> > PostAutosVehicle(AutosVehicle autosVehicle) { _context.AutosVehicle.Add(autosVehicle); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAutosVehicle", new { id = autosVehicle.AutoId }, autosVehicle)); }
public async Task <ActionResult <IEnumerable <AutosVehicle> > > SearchCars (AutosVehicle input, int PowerFrom, int PowerTo, int FromMil, int ToMil, string ABS, string fourwheel) { var A = await _context.AutosVehicle.Where(a => a.IsSold != 1 && a.IsReserved != 1 && (input.MakeId.Contains("x") || a.MakeId == input.MakeId) //&& (input.ModlId.Contains("x") || a.ModlId == input.ModlId) && (input.Acolor.Contains("x") || a.Acolor == input.Acolor) && (input.BodyId.Contains("x") || a.BodyId == input.BodyId) && (input.Engine.Contains("x") || a.Engine == input.Engine) && (input.FuelType.Contains("x") || a.FuelType == input.FuelType) && ((PowerTo == 0) || (a.Power >= PowerFrom && a.Power <= PowerTo)) && ((ToMil == 0) || ((a.Mileag >= FromMil) && (a.Mileag <= ToMil))) && ((input.Volume == 0) || a.Volume == input.Volume) && ((input.Cosumption == 0) || a.Cosumption == input.Cosumption) && ((input.AuYear == 0) || a.AuYear == input.AuYear) && ((input.NoOfDoors == 0) || a.NoOfDoors == input.NoOfDoors) && ((input.SellPri == 0) || a.SellPri == input.SellPri) && ((input.Seater == 0) || a.Seater == input.Seater) ) .Include(a => a.CarBody) .Include(a => a.CarMake) .Include(a => a.CarModel) .Include(a => a.CarCategory) .Include(a => a.AutosFeatures) .Include(a => a.AutosImages) .ToListAsync(); return(A); }
public async Task <ActionResult> GetFeaturedAutos() { AutosVehicle autosVehicle = new AutosVehicle(); try { var url = "https://localhost:44363/api/AutosVehicles/GetFeatuedAutos"; var client = new HttpClient(); var response = await client.GetAsync(url); var AutosFeatured = response.Content.ReadAsStringAsync().Result; try { AutosVehicle[] a = JsonConvert.DeserializeObject <AutosVehicle[]>(AutosFeatured); ViewBag.AutosVehicle = a; return(View("Featured_cars", a)); } catch { Error err = new Error(); err.ErrorMessage = "All our cars are Featured cars"; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } } catch { Error err = new Error(); err.ErrorMessage = "All our cars are Featured cars"; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } }
public async Task <IActionResult> PutAutosVehicle(int id, AutosVehicle autosVehicle) { if (id != autosVehicle.AutoId) { return(BadRequest()); } _context.Entry(autosVehicle).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AutosVehicleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> DeleteConfirmed(int id) { AutosVehicle autosVehicle = await db.AutosVehiclesCrollers.FindAsync(id); db.AutosVehiclesCrollers.Remove(autosVehicle); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> SearchCars(FormCollection data) { var qry = "PowerFrom=" + data["PowerFrom"] + "&PowerTo=" + data["PowerTo"] + "&FromMil=" + data["FromMil"] + "&ToMil=" + data["ToMil"]; Dictionary <string, string> form = data.AllKeys.ToDictionary(k => k, v => data[v]); AutosVehicle autosVehicle = new AutosVehicle(); var myContent = JsonConvert.SerializeObject(form); try { var data1 = new StringContent(myContent + qry, Encoding.UTF8, "application/json"); var url = "https://localhost:44363/api/AutosVehicles/SearchCars"; var client = new HttpClient(); var response = await client.PostAsync(url, data1); var AutosSearch = response.Content.ReadAsStringAsync().Result; AutosVehicle[] a = JsonConvert.DeserializeObject <AutosVehicle[]>(AutosSearch); ViewBag.AutosVehicle = a; ViewBag.MakeId = data["MakeId"]; ViewBag.ModlId = data["ModlId"]; ViewBag.BodyId = data["BodyId"]; ViewBag.AuYear = data["AuYear"]; ViewBag.Transmission = data["Transmission"]; ViewBag.SellPri = data["SellPri"]; ViewBag.FuelType = data["FuelType"]; ViewBag.from = data["from"]; ViewBag.to = data["to"]; ViewBag.fourbyfour = data["fourbyfour"]; ViewBag.vatdeduction = data["vatdeduction"]; ViewBag.FromMil = data["FromMil"]; ViewBag.ToMil = data["ToMil"]; ViewBag.PowerFrom = data["PowerFrom"]; ViewBag.PowerTo = data["PowerTo"]; ViewBag.FromYear = data["FromYear"]; ViewBag.ToYear = data["ToYear"]; ViewBag.PowerFrom = data["PowerFrom"]; ViewBag.PowerTo = data["PowerTo"]; ViewBag.Volume = data["Volume"]; ViewBag.Engine = data["Engine"]; ViewBag.Seater = data["Seater"]; ViewBag.Cosumption = data["Cosumption"]; ViewBag.NoOfDoors = data["NoOfDoors"]; ViewBag.Acolor = data["Acolor"]; return(View("MainView", a)); } catch (Exception) { Error err = new Error(); err.ErrorMessage = "Sorry we found no cars with these filters"; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } }
// GET: AutosVehicles/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AutosVehicle autosVehicle = await db.AutosVehiclesCrollers.FindAsync(id); if (autosVehicle == null) { return(HttpNotFound()); } return(View(autosVehicle)); }
public async Task <ActionResult> Edit([Bind(Include = "AutoId,Acolor,Street,statNm,cityNM,ZipCod,cnName,MILEAG,sellpri,Auyear,transmission,fueltype,power,valume,Engine,Seater,Cosumption,NoOfDoors,IsSold,IsReserved,IsFeataured,IsTrendy,MakeId,ModlId,BodyId,CatgId,sellID")] AutosVehicle autosVehicle) { if (ModelState.IsValid) { db.Entry(autosVehicle).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BodyId = new SelectList(db.CarBodies, "BodyId", "BDDesc", autosVehicle.BodyId); ViewBag.CatgId = new SelectList(db.CarCategories, "CatgId", "CgDesc", autosVehicle.CatgId); ViewBag.MakeId = new SelectList(db.CarMakes, "MakeId", "MkDesc", autosVehicle.MakeId); ViewBag.ModlId = new SelectList(db.CarModels, "ModlId", "MdDesc", autosVehicle.ModlId); return(View(autosVehicle)); }
// GET: AutosVehicles/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AutosVehicle autosVehicle = await db.AutosVehiclesCrollers.FindAsync(id); if (autosVehicle == null) { return(HttpNotFound()); } ViewBag.BodyId = new SelectList(db.CarBodies, "BodyId", "BDDesc", autosVehicle.BodyId); ViewBag.CatgId = new SelectList(db.CarCategories, "CatgId", "CgDesc", autosVehicle.CatgId); ViewBag.MakeId = new SelectList(db.CarMakes, "MakeId", "MkDesc", autosVehicle.MakeId); ViewBag.ModlId = new SelectList(db.CarModels, "ModlId", "MdDesc", autosVehicle.ModlId); return(View(autosVehicle)); }
public async Task <ActionResult> GetAutoById(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AutosVehicle autosVehicle = new AutosVehicle(); using (var client = new HttpClient()) { //Passing service base url client.DefaultRequestHeaders.Clear(); //Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource PostSiteUsers using HttpClient UriBuilder builder = new UriBuilder("https://localhost:44363/api/AutosVehicles/GetAutoById?"); builder.Query = "id=" + id; HttpResponseMessage Res = await client.GetAsync(builder.Uri); if (Res.IsSuccessStatusCode) { var auto = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list AutosVehicle a = JsonConvert.DeserializeObject <AutosVehicle>(auto); ViewBag.AutosVehicle = a; ViewBag.mystring = id; ViewBag.Error = null; return(View("CarDetails", a)); } else { Error err = new Error(); err.ErrorMessage = "Sorry no car found on this id " + id; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } } }
public async Task <ActionResult> SearchCarsBrands(string brand) { AutosVehicle autosVehicle = new AutosVehicle(); using (var client = new HttpClient()) { //Passing service base url client.DefaultRequestHeaders.Clear(); //Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource PostSiteUsers using HttpClient UriBuilder builder = new UriBuilder("https://localhost:44363/api/AutosVehicles/SearchCarsBrands?"); builder.Query = "Brand=" + brand; HttpResponseMessage Res = await client.GetAsync(builder.Uri); if (Res.IsSuccessStatusCode) { var Brand = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list AutosVehicle[] a = JsonConvert.DeserializeObject <AutosVehicle[]>(Brand); ViewBag.AutosVehicle = a; ViewBag.mystring = brand; ViewBag.Error = null; return(View("MainView", a)); //return Json(a); } else { Error err = new Error(); err.ErrorMessage = "Sorry no cars found for" + brand + "Brand"; ViewBag.Error = err; ViewBag.AutosVehicle = null; return(View("Error", err)); } } }