public async Task <IActionResult> EditVehicle(int id) { var client = _httpClientFactory.CreateClient(Constants.ClientWithToken); //get vehicle by id var response = await client.GetAsync <CarsDTO>(string.Format(Constants.Routes.GetCarById, id)); var getAllLocations = await client.GetAsync(Constants.Routes.GetAllLocations); var getAllCarManuacturers = await client.GetAsync(Constants.Routes.GetAllCarManuacturer); var result = await getAllLocations.Content.ReadAsAsync <IList <LocationDTO> >(); var result2 = await getAllCarManuacturers.Content.ReadAsAsync <IList <CarManufacturerDTO> >(); ViewBag.CarManufacturer = new SelectList(result2 ?? new List <CarManufacturerDTO>(), "Id", "Name"); ViewBag.location = new SelectList(result ?? new List <LocationDTO>(), "LocationId", "LocationName"); var items = response.Object; items.Colors = StringToEnumConverter.ParseEnum <CarColor>(items.Color); items.Statuses = StringToEnumConverter.ParseEnum <CarStatus>(items.Status); items.Conditions = StringToEnumConverter.ParseEnum <CarCondition>(items.Condition); if (response.ValidationErrors.Count > 0) { ViewBag.errors = "An Error Occurred " + response.Code + ": " + response.ShortDescription; return(RedirectToAction("GetAllCars")); } else { return(View(items)); } }
public async Task <IActionResult> AddCarPost(CarsDTO model) { var client = _httpClientFactory.CreateClient(Constants.ClientWithToken); model.Color = model.Colors.ToString(); model.Status = model.Statuses.ToString(); model.Condition = model.Conditions.ToString(); CarColor col = StringToEnumConverter.ParseEnum <CarColor>("Ash"); var response = await client.PostAsJsonAsync <CarsDTO, bool>(Constants.Routes.AddCar, model); var items = response.Object; if (response.ValidationErrors.Count > 0) { TempData["error"] = "An Error Occurred " + response.Code + ": " + response.ShortDescription; return(View("AddNewCar", model)); //return RedirectToAction("AddNewCar"); } else { //return View("AddNewCar", model); return(RedirectToAction("GetAllCars")); } }