public ActionResult AddLocation(LocationViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var location = new Location(); if (model.Id == 0) { location.StreetAddress = model.StreetAddress; location.City = model.City; location.ZipCode = model.ZipCode; location.Country = model.Country; _locationApiCall.PostApiCall(location); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Location added successfully"; } else { location = _locationApiCall.GetT(model.Id); location.StreetAddress = model.StreetAddress; location.City = model.City; location.ZipCode = model.ZipCode; _locationApiCall.PutApiCall(location, model.Id); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Location edited successfully"; } return(RedirectToAction("Index")); } catch (Exception ex) { TempData["SuccessResultF"] = false; TempData["SuccessResultM"] = "Something went wrong."; throw ex; } }
public IActionResult AddModel(CarModelViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { if (model.Id == 0) { var carModel = new Model { BrandId = model.BrandId, Name = model.Name }; _modelApiCall.PostApiCall(carModel); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Model added successfully"; } else { var carModel = _modelApiCall.GetT(model.Id); carModel.BrandId = model.BrandId; carModel.Name = model.Name; _modelApiCall.PutApiCall(carModel, model.Id); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Model edited successfully"; } } catch (Exception) { TempData["SuccessResultF"] = false; TempData["SuccessResultM"] = "Something went wrong."; throw; } return(RedirectToAction("Models", new { brandId = model.BrandId })); }
public IActionResult AddBrand(BrandViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { if (model.Id == 0) { var brand = new Brand { Name = model.Name }; _brandApiCall.PostApiCall(brand); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Brand added successfully"; } else { var brand = _brandApiCall.GetT(model.Id); brand.Name = model.Name; _brandApiCall.PutApiCall(brand, model.Id); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Brand edited successfully"; } } catch (Exception ex) { TempData["SuccessResultF"] = false; TempData["SuccessResultM"] = "Something went wrong."; throw ex; } return(RedirectToAction("Index")); }
public IActionResult AddFuel(int id, FuelViewModel model) { if (id == 0) { if (!ModelState.IsValid) { return(View(model)); } try { var fuel = new Fuel(); if (model.Id == 0) { fuel.Id = model.Id; fuel.Name = model.Name; var result = _apiGetCalls.PostApiCall(fuel); if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); } catch { return(View()); } } else { try { var fuel = new Fuel { Id = model.Id, Name = model.Name }; var result = _apiGetCalls.PutApiCall(fuel, id); if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(RedirectToAction("Index")); } catch { return(View()); } } }
public IActionResult Add(CarViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var car = new Car(); if (model.Id == 0) { car.CarNumber = model.CarNumber; car.BrandId = model.BrandId; car.ModelId = model.ModelId; car.ModelYear = model.ModelYear; car.NumberOfDoors = model.NumberOfDoors; car.CarCapacity = model.CarCapacity; car.CarColor = model.CarColor; car.FuelTypeId = model.FuelTypeId; car.TransmisionTypeId = model.TransmisionTypeId; car.PriceForDay = model.PriceForDay; car.Description = model.Description; car.CarLocationId = model.LocationId; car.CreateOnDate = DateTime.Now; car.LastModifiedOnDate = DateTime.Now; car.CreateByUserId = _userManager.GetUserId(User); car.LastModifiedByUserId = _userManager.GetUserId(User); car.IsDeleted = false; _carApiGetCall.PostApiCall(car); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Car added successfully"; } else { car = _carApiGetCall.GetT(model.Id); car.CarNumber = model.CarNumber; car.BrandId = model.BrandId; car.ModelId = model.ModelId; car.ModelYear = model.ModelYear; car.NumberOfDoors = model.NumberOfDoors; car.CarCapacity = model.CarCapacity; car.CarColor = model.CarColor; car.FuelTypeId = model.FuelTypeId; car.TransmisionTypeId = model.TransmisionTypeId; car.PriceForDay = model.PriceForDay; car.Description = model.Description; car.CarLocationId = model.LocationId; car.LastModifiedByUserId = _userManager.GetUserId(User); car.LastModifiedOnDate = DateTime.Now; car.IsDeleted = false; _carApiGetCall.PutApiCall(car, model.Id); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "Car edited successfully"; } //if (model.Image != null && model.Image.Length > 0) //{ // _carService.UploadImage(model.Image, car.Id); //} return(RedirectToAction("Index")); } catch (Exception ex) { TempData["SuccessResultF"] = false; TempData["SuccessResultM"] = "Something went wrong."; throw ex; } }