public Car ConvertVMToCar(CarVM model) { Car result = new Car() { AddDate = model.AddDate, AddUserId = model.AddUserId, //BodyStyle = (model.BodyStyle == "Car" || model.BodyStyle == "C") ? "C" : (model.BodyStyle == "Truck" || model.BodyStyle == "T") ? "T" : (model.BodyStyle == "Van" || model.BodyStyle == "V") ? "V" : "S", //Transmission = (model.Transmission == "Automatic" || model.Transmission == "A") ? "A" : "M", //Type = (model.Type == "New" || model.Type == "N") ? "N" : "U", BodyStyle = model.BodyStyle, Transmission = model.Transmission, Type = model.Type, CarId = model.CarId, Color = model.Color, Description = model.Description, EditDate = model.EditDate.Year > 1900 ? model.EditDate : DateTime.Parse("01/01/1900"), EditUserId = model.EditUserId, Interior = model.Interior, Mileage = model.Mileage, ModelId = model.ModelId, MSRP = model.MSRP, Picture = model.Picture, ReleaseYear = model.ReleaseYear, SalePrice = model.SalePrice, VinNo = model.VinNo, IsFeature = model.IsFeature }; return(result); }
public async Task <IActionResult> Edit(int id, CarVM CarVM) { if (id != CarVM.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Car car = _mapper.Map <CarVM, Car>(CarVM); _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(CarVM.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(CarVM)); }
public ActionResult UpdateCar(int?id, CarVM vmodel) { if (Session["LoggedIn"] != null) { var db = new MyDBEntities(); var carToUpdate = db.Cars.Find((int)id); if (ModelState.IsValid) { if (carToUpdate != null) { carToUpdate.Id = (int)id; carToUpdate.Make = vmodel.Make; carToUpdate.Model = vmodel.Model; carToUpdate.CostPD = vmodel.CostPD; carToUpdate.Quantity = vmodel.Quantity; db.SaveChanges(); } } ViewData["Message"] = "Record updated"; return(RedirectToAction("DisplayCars", "Car")); } else { Response.Redirect("../User/Login"); //making sure you substitute “Login” for whatever your login method is actually called if different } return(View(vmodel)); }
public ActionResult CarGridViewLinked(CarVM carVM) { if (ModelState.IsValid) { try { if (carVM != null) { Car car = carVM.Car; car.CreatedBy = _RecordService.GetCurrentUser().FullName; db.HseqRecords.Add(car); db.SaveChanges(); HseqRecord sourceRecord = db.HseqRecords.Find(carVM.SourceRecordId); car.LinkedRecords.Add(sourceRecord); sourceRecord.LinkedRecords.Add(car); db.SaveChanges(); } } catch (Exception e) { ViewData["EditError"] = e.Message; return(PartialView("_CarNewView", carVM)); } } else { var errors = ModelState.Values.SelectMany(v => v.Errors); ViewData["EditError"] = "Please, correct all errors."; return(PartialView("_CarNewView", carVM)); } return(PartialView("_MainContentCallbackPanel")); }
public async Task <IActionResult> Edit(CarVM carVM) { if (!ModelState.IsValid) { return(View(carVM)); } bool result; var car = _mapper.Map <Car>(carVM); if (car.Id != 0) { result = await _repository.UpdateCar(car); } else { result = await _repository.AddCar(car); } if (result) { _toastNotification.AddSuccessToastMessage("Editing was successful"); } else { _toastNotification.AddErrorToastMessage("It was unsuccessful"); } return(RedirectToAction("Index")); }
//public IActionResult Create(string FileName) //{ // if (!string.IsNullOrEmpty(FileName)) // ViewBag.ImgPath = "/Images/" + FileName; // return View(); //} public async Task <IActionResult> Create(bool migrate) { if (migrate) { var client = new HttpClient(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); try { var response = await client.GetAsync("http://localhost:6000/api/Car"); if (response.IsSuccessStatusCode) { var result = client.GetStringAsync("http://localhost:6000/api/Car"); var json = await result; Car car = JsonConvert.DeserializeObject <Car>(json); var vm = new CarVM() { Car = car }; return(View(vm)); } } catch (Exception ex) { ViewBag.ErrorMsg = ex.Message; } } return(View()); }
public ActionResult Add() { CarVM vm = new CarVM(); vm.aracmarka = _carBrandService.GetActive(); return(View(vm)); }
public IResponseDTO EditCar(CarVM model) { try { var DbCar = _mapper.Map <Car>(model); var entityEntry = _CarRepositroy.Update(DbCar); int save = _unitOfWork.Commit(); if (save == 200) { _response.Data = model; _response.IsPassed = true; _response.Message = "Ok"; } else { _response.Data = null; _response.IsPassed = false; _response.Message = "Not saved"; } } catch (Exception ex) { _response.Data = null; _response.IsPassed = false; _response.Message = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : ""); } return(_response); }
// GET: Cars public ActionResult Index(string search) { //get list of cars from db var cars = db.Cars.ToList(); // create list of cars from viewmodel var carsVM = new List <CarVM>(); //create list for filtered cars var carsSearchVM = new List <CarVM>(); foreach (var car in cars) { carsVM.Add(CarVM.MapTo(car)); } if (search == null) { return(View(carsVM)); } //populating list with filtered cars carsSearchVM = carsVM.Where(x => x.Make.Contains(search)).ToList <CarVM>(); return(View(carsSearchVM)); }
public HttpResponseMessage newcar(CarVM carVM) { try { if (!_CarMasterService.CheckDuplicateCarName(carVM.Name)) { int result = _CarMasterService.CarRegistration(carVM); if (result > 0) { return(Request.CreateResponse(HttpStatusCode.Created, "new car added successful!")); } else { return(Request.CreateResponse(HttpStatusCode.OK, "something went wrong")); } } else { return(Request.CreateResponse(HttpStatusCode.OK, "car name already exist")); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, ex.InnerException.Message)); } }
public ActionResult Create(CarVM carVM, HttpPostedFileBase image) { try { var fileName = Path.GetFileName(image.FileName); var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName); image.SaveAs(path); carVM.Image = fileName; carVM.DealerId = User.Identity.GetUserId(); if (ModelState.IsValid) { if (carAppService.SaveNewCar(carVM)) { return(RedirectToAction("Index")); } else { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } } else { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } } catch (Exception) { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } }
public async Task <IActionResult> Create([Bind("Name, SeatCount, FuelConsumption, BrandId")] CarVM car) { if (ModelState.IsValid) { try { await carService.UpdateCarAsync(car.Adapt <CarDTO>()); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var brands = await brandService.GetAllBrandsAsync(); ViewData["Brands"] = new SelectList(brands, "Id", "Name"); return(View(brands)); }
public ActionResult SelectMileageAndPaybackTime(int?id) { id = id ?? 1; ViewData["Username"] = HttpContext.Request.Cookies.Get("username").Value; GetResponse data = TempData.Peek("Data") as GetResponse; CarVM car = new CarVM(); if (data == null) { CarBL carBL = new CarBL(); try { data = carBL.GetCarData(); TempData["Data"] = data; } catch (Exception e) { ViewData["Error"] = e.Message; // redirect to error page with error message } } ViewData["Mileages"] = data.Mileages; ViewData["PaybackTimes"] = data.PaybackTimes; car = data.Cars.AsQueryable().Where(x => x.CarId == id).First(); ViewData["Car"] = car; return(View()); }
public async Task <CarVM> GetCar(int?id) { var obj = new CarVM(); try { CarViewModel data = await _context.Cars.Where(p => p.ID == id).Select(p => new CarViewModel() { ID = p.ID, BrandId = p.Model.BrandID, BrandName = p.Model.Brand.BrandName, CategoryId = p.CategoryId, CategoryName = p.Category.CategoryName, ColorId = p.ColorId, ColorCode = p.Color.ColorCode, ColorName = p.Color.ColorName, CreateDate = p.CreateDate, ModelId = p.ModelId, ModelName = p.Model.ModelName, Price = p.Price, Quantity = p.Quantity }).FirstOrDefaultAsync(); obj.CarViewModel = data; obj.isAccept = true; } catch (Exception) { obj.isAccept = false; } return(obj); }
// GET: Dealer/Car/Create public ActionResult Create() { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name"); CarVM carVM = new CarVM(); return(View(carVM)); }
public JsonResult InsertOrUpdate(CarVM carVM, int id_car) { try { var json = JsonConvert.SerializeObject(carVM); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); if (carVM.id_car == 0) { var result = client.PostAsync("cars", byteContent).Result; return(Json(result)); } else if (carVM.id_car == id_car) { var result = client.PutAsync("cars/" + id_car, byteContent).Result; return(Json(result)); } return(Json(404)); } catch (Exception ex) { throw ex; } }
public ActionResult UpdateCar(int?id) { var db = new MyDBEntities(); CarVM vmodel = new CarVM(); if (Session["LoggedIn"] != null) { if (Session["id"] == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var carToUpdate = db.Cars.Find((int)id); vmodel.Id = (int)id; vmodel.Make = carToUpdate.Make; vmodel.Model = carToUpdate.Model; vmodel.CostPD = carToUpdate.CostPD; vmodel.Quantity = carToUpdate.Quantity; } else { Response.Redirect("../User/Login"); //making sure you substitute “Login” for whatever your login method is actually called if different } return(View(vmodel)); }
public ActionResult Add(CarVM model) { if (model.Type == "N" && model.Mileage > 1000) { ModelState.AddModelError("Mileage", "Mileage of new vehicle must be between 0 and 1000"); } if (ModelState.IsValid) { var tmp = _repo.AddCar(model); if (tmp.Result.Success) { return(RedirectToAction("List")); } else { ModelState.AddModelError("Vehicle", "Cannot add vehicle"); } } model.SetMakeItems(_repo.GetMakeList()); model.SetBodyStyleItems(); model.SetColorItems(); model.SetInteriorItems(); model.SetTransmissionItems(); model.SetTypeItems(); return(View(model)); }
public ActionResult Edit(CarVM model, string Delete, string Save) { if (!string.IsNullOrEmpty(Delete)) { _repo.DeleteCar(model.CarId); return(RedirectToAction("List")); } else { if (model.Type == "N" && model.Mileage > 1000) { ModelState.AddModelError("Mileage", "Mileage of new vehicle must be between 0 and 1000"); } if (ModelState.IsValid) { var tmp = _repo.UpdateCar(model); if (tmp.Result.Success) { return(RedirectToAction("List")); } else { ModelState.AddModelError("Vehicle", "Cannot edit vehicle"); } } model.SetMakeItems(_repo.GetMakeList()); model.SetBodyStyleItems(); model.SetColorItems(); model.SetInteriorItems(); model.SetTransmissionItems(); model.SetTypeItems(); return(View(model)); } }
public bool UpdateCar(CarVM carVM) { var car = Mapper.Map <Car>(carVM); TheUnitOfWork.Car.Update(car); TheUnitOfWork.Commit(); return(true); }
public IActionResult Edit(CarVM vm) { if (ModelState.IsValid) { _carRepository.EditCar(vm.Car); return(RedirectToAction(nameof(Manage))); } return(View(vm)); }
public IActionResult CreateCar(CarVM carVM) { var create = _iCar.Create(carVM); if (create > 0) { return(Ok(create)); } return(BadRequest("Not Successfully")); }
public IActionResult UpdateCarCleaning(CarVM carToUpdate) { if (!ModelState.IsValid) { return(View()); } service.UpdateCarCleaning(carToUpdate); return(RedirectToAction("CarDetails", new { id = carToUpdate.Id })); }
public IActionResult AddCar(CarVM carToAdd) { if (!ModelState.IsValid) { return(View()); } service.AddCarToDb(carToAdd); return(RedirectToAction(nameof(AddCar))); }
public IActionResult EditCar(int id, CarVM carVM) { var edit = _iCar.Update(carVM, id); if (edit > 0) { return(Ok(edit)); } return(BadRequest("Not Successfully")); }
public CarVM ConvertCarToVM(Car model) { String path = HttpContext.Current.Server.MapPath("~/Content/Images/"); CarVM result = new CarVM() { AddDate = model.AddDate, AddUserId = model.AddUserId, //BodyStyle = model.BodyStyle == "C" ? "Car" : model.BodyStyle == "T" ? "Truck" : model.BodyStyle == "V" ? "Van" : "SUV", BodyStyle = model.BodyStyle, CarId = model.CarId, Color = model.Color, Description = model.Description, EditDate = model.EditDate, EditUserId = model.EditUserId, Interior = model.Interior, Mileage = model.Mileage, ModelId = model.ModelId, MSRP = model.MSRP, ReleaseYear = model.ReleaseYear, SalePrice = model.SalePrice, //Transmission = model.Transmission == "A" ? "Automatic" : "Manual", //Type = model.Type == "N" ? "New" : "Used", Transmission = model.Transmission, Type = model.Type, VinNo = model.VinNo, IsFeature = model.IsFeature, Picture = model.Picture, PictureUrl = path + "Inventory_" + model.CarId + ".jpg", PictureName = "Inventory_" + model.CarId + ".jpg", IsPurchase = GetSaleList().Count(s => s.CarId == model.CarId) > 0, AddUser = GetUserById(model.AddUserId), Model = GetModelById(model.ModelId), Make = GetMakeById(GetModelById(model.ModelId).MakeId), Result = ReturnSuccess(), MakeId = GetModelById(model.ModelId).MakeId }; if (result.Picture != null) { using (BinaryWriter b = new BinaryWriter(File.OpenWrite(result.PictureUrl))) { b.Write(result.Picture); b.Flush(); b.Close(); } result.PictureUrl = @CurrentUrl + "/Content/Images/" + result.PictureName; } else { result.PictureUrl = @CurrentUrl + "/Content/Images/no-image.png"; } return(result); }
public bool SaveNewCar(CarVM carVM) { bool result = false; var car = Mapper.Map <Car>(carVM); if (TheUnitOfWork.Car.Insert(car)) { result = TheUnitOfWork.Commit() > new int(); } return(result); }
public IActionResult EditCarAndDriver(int id) { CarVM model = new CarVM(); var editCar = _service.Car.GetCar(id); var editCarDriver = _service.CarDriver.GetCarDriverByCar(editCar.Id); model.Car = _mapper.Map <CarDTO>(editCar); model.CarDriver = _mapper.Map <CarDriverDTO>(editCarDriver); return(View(model)); }
public ActionResult Edit(CarVM carVM) { if (ModelState.IsValid) { var car = CarVM.MapTo(carVM); db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carVM)); }
public ActionResult Update(Guid id) { CarVM vm = new CarVM(); vm.araba = _carService.GetById(id); if (vm.araba != null) { ViewBag.araclar = _carService.GetActive(); vm.aracmarka = _carBrandService.GetActive(); } return(View(vm)); }