public IHttpActionResult EditCar([FromUri] string carId, [FromBody] CarEditViewModel carViewModel) { Car car = _carService.GetCarById(carId); if (car == null) { return(BadRequest()); } if (ModelState.IsValid) { car.Model = carViewModel.Model; car.Brand = carViewModel.Brand; car.MainImage = carViewModel.MainImage; car.NumberOfDoors = carViewModel.NumberOfDoors; car.NumberOfSeats = carViewModel.NumberOfSeats; if (_carService.EditCar(car)) { var carObject = JsonConvert.SerializeObject(car, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); _carHub.Clients.All.carUpdated(carObject); return(Ok()); } return(BadRequest()); } return(BadRequest(ModelState)); }
public ActionResult CarGridViewUpdate(CarEditViewModel carEditVM) { if (ModelState.IsValid) { try { if (carEditVM != null) { Car car = db.CarRecords.Find(carEditVM.HseqRecordID); Mapper.Map(carEditVM, car); db.Entry(car).State = EntityState.Modified; db.SaveChanges(); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; return(PartialView("_CarEditView", carEditVM)); } return(PartialView("_MainContentCallbackPanel")); }
public ActionResult EditCar(CarEditViewModel model) { if (model.Car.Id != 0) { _repository.Update(model.Car); } Car car = model.Car.Id == 0 ? model.Car : _repository.Select <Car>().Include(c => c.Owners).FirstOrDefault(c => c.Id == model.Car.Id); if (Request.Form["ownersSelect"] != null) { int[] owners = Request.Form["ownersSelect"].Split(',').Select(n => Convert.ToInt32(n)).ToArray(); List <Owner> ownersList = _repository.Select <Owner>().Where(o => owners.Contains(o.Id)).ToList(); car.Owners.Clear(); ownersList.ForEach(o => car.Owners.Add(o)); } if (ModelState.IsValid) { if (model.Car.Id == 0) { _repository.Insert(car); } else { _repository.Update(car); } return(RedirectToAction("Cars")); } return(View(new CarEditViewModel() { Car = car, Owners = _repository.Select <Owner>().Include(c => c.Cars).ToList() })); }
public async Task <IActionResult> Edit(CarEditViewModel car) { ; await this.carsService.EditCarAsync(car); return(Ok("Done")); }
public IActionResult Edit(int id, CarEditViewModel car) { var userId = userManager.GetUserId(this.User); if (ModelState.IsValid) { Car carToDb = new Car { Id = car.Id, Brand = car.Brand, Category = car.Category, Model = car.Model, Year = car.Year, Engine = car.Engine, HorsePower = car.HorsePower, Type = car.Type, ImageUrl = car.ImageUrl, UserId = userId }; db.Update(carToDb); db.SaveChanges(); return(RedirectToAction("All")); } return(View(car)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,OwnerId,Model,Year,Color")] CarEditViewModel car) { if (id != car.Id) { return(NotFound()); } try { if (ModelState.IsValid) { var serializedItem = JsonSerializer.Serialize(car); var response = await client.PutAsync(APIDATA.URL + $"Cars/{id}", new StringContent(serializedItem, Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } else { AddModelError(); } } } catch { AddModelError(); } var json = await client.GetStringAsync(APIDATA.URL + $"Users/Select"); var users = JsonSerializer.Deserialize <IEnumerable <SelectItem> >(json); ViewData["OwnerId"] = new SelectList(users, "Value", "Text", car.OwnerId); return(View(car)); }
public ViewResult Edit(Guid id) { Car car = _carsrepository.GetCar(id); CarEditViewModel model = new CarEditViewModel { Id = car.Id, BodyType = car.BodyType, Color = car.Color, EngineSize = car.EngineSize, FuelType = car.FuelType, GearboxType = car.GearboxType, Make = car.Make, Model = car.Model, Milage = car.Milage, PowerHP = car.PowerHP, PowerkW = car.PowerkW, ProductionYear = car.ProductionYear, RegistrationDate = car.RegistrationDate, RegistrationNumber = car.RegistrationNumber, ServiceInterval = car.ServiceInterval, SpecType = car.SpecType, VIN = car.VIN }; return(View(model)); }
public async Task <bool> Edit(int id, CarEditViewModel model) { Require.ThatIntIsPositive(id); Require.ThatObjectIsNotNull(model); Car car = this.cars.GetById(id); if (car != null) { car.Brand = model.Brand; car.CarModel = model.CarModel; car.Year = model.Year; car.HasAirConditioner = model.HasAirConditioner; if (model.NewImage != null) { using (var ms = new MemoryStream()) { await model.NewImage.CopyToAsync(ms); car.Image = ms.ToArray(); } } await this.cars.UpdateAsync(car); return(true); } return(false); }
private void ValidateCarData(CarEditViewModel data, ModelStateDictionary state) { if (data.ManufactureDate > DateTime.Today) { state.AddModelError("ManufactureDate", "Mustn't be a future date"); } if (!new Regex("[A-Z]{3}[' ']?[0-9]{3}").IsMatch(data.LicensePlate)) { state.AddModelError("LicensePlate", "Must be in format XXX 000"); } if (data.Documents != null) { for (var i = 0; i < data.Documents.Count; i++) { if (data.Documents[i].StartDate > data.Documents[i].EndDate) { state.AddModelError("Documents[" + i + "].StartDate", "Start date mustn't be greater than end date"); } } } if (data.MileagePoints != null) { for (var i = 0; i < data.MileagePoints.Count; i++) { if (data.MileagePoints[i].Mileage < 0) { state.AddModelError("MileagePoints[" + i + "].Mileage", "Mileage must be a positive integer"); } } } }
public async Task <IActionResult> Edit(int id) { if (id > 0) { var cars = await _mediator.Send(new GenericQueryWithProjectCommand <Car, CarEditViewModel>( new BaseCarQuery() { ID = id, Includes = new List <System.Linq.Expressions.Expression <Func <Car, object> > >() { x => x.Brand } })); CarEditViewModel model = cars.Results.FirstOrDefault(); QueryResult <Brand> output = await _mediator.Send(new GenericQueryCommand <Brand>(new BaseBrandQuery())); model.Brands = output.Results.ToList(); return(base.PartialView(model)); } return(NotFound()); }
public IActionResult EditCarInfo(int id, CarEditViewModel data) { if (m_userData.Get(m_userManager.GetUserId(User)).Type != UserType.Manager) { return(Content("Oops! Nothing to see here.")); } if (!ModelState.IsValid) { return(View(data)); } ValidateCarData(data, ModelState); if (!ModelState.IsValid) { return(View(data)); } Car modified = m_carData.Get(id); if (modified == null) { return(View(data)); } m_carData.Update(data); m_documentData.UpdateCarsDocuments(modified, data.Documents); m_mileagePointData.UpdateCarsMileagePoints(modified, data.MileagePoints?. Select(p => p as MileagePointBase).ToList()); m_carData.SaveChanges(); m_carData.UpdateState(id); m_carData.SaveChanges(); return(RedirectToAction("ViewCarInfo", new { id = data.Id })); }
public IActionResult Edit(CarEditViewModel model) { // check if we have valid data in the form if (ModelState.IsValid) { Car car = _carRepository.GetCarById(model.Id); car.CarName = model.CarName; car.VehicleClass = model.VehicleClass; car.Capacity = model.Capacity; car.CarType = model.CarType; car.Price = model.Price; if (model.Photo != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "img", model.ExistingPhotoPath); System.IO.File.Delete(filePath); car.PhotoPath = ProcessUploadedFile(model); _carRepository.Update(car); return(RedirectToAction("index", "home")); } else { car.PhotoPath = "~/img/noaccess.jpg"; } } return(View()); }
public IActionResult Edit(CarEditViewModel viewModel) { if (ModelState.IsValid) { Car car = _carsrepository.GetCar(viewModel.Id); car.Id = viewModel.Id; car.BodyType = viewModel.BodyType; car.Color = viewModel.Color; car.EngineSize = viewModel.EngineSize; car.FuelType = viewModel.FuelType; car.GearboxType = viewModel.GearboxType; car.Make = viewModel.Make; car.Model = viewModel.Model; car.Milage = viewModel.Milage; car.PowerHP = viewModel.PowerHP; car.PowerkW = viewModel.PowerkW; car.ProductionYear = viewModel.ProductionYear; car.RegistrationDate = viewModel.RegistrationDate; car.RegistrationNumber = viewModel.RegistrationNumber; car.ServiceInterval = viewModel.ServiceInterval; car.SpecType = viewModel.SpecType; car.VIN = viewModel.VIN; _carsrepository.Update(car); return(RedirectToAction("details", "cars", new { id = car.Id })); } return(RedirectToAction("edit", "cars", new { id = viewModel.Id })); }
public void Constructor_CarDataServiceIsNull_ThrowException() { int id = 1; ICarDataService carDataService = null; //Parent entities var viewModelEdit = new CarEditViewModel(carDataService); }
public void Car_New_CanSaveCarIsTrue() { ICarDataService carDataService = new DesignCarDataService(); //Parent entities var viewModelEdit = new CarEditViewModel(carDataService); Assert.IsTrue(viewModelEdit.CanSaveCar); }
public void Constructor_CarIsNull_ThrowException() { ICarDataService carDataService = new DesignCarDataService(); //Parent entities Car car = null; var viewModelEdit = new CarEditViewModel(car, carDataService); }
public bool Put(CarEditViewModel model) { return(CarsDAL.Put(new Car() { Id = model.Id, OwnerId = model.OwnerId, Model = model.Model, Year = model.Year, Color = model.Color })); }
public IActionResult Edit(CarEditViewModel model) { Car car = carRepository.GetCarByID(model.CarID); car.Manufacturer = model.Manufacturer; car.MOT = model.MOT; car.DriverID = model.SelectedDriverId; carRepository.UpdateCar(car); carRepository.Save(); return(RedirectToAction("Index")); }
public CarEditView(int id) : this() { var carDataService = ServiceProvider.Instance.CarDataService; //TO DO: Consider parent relations source (ex. are parent relations load manualy or from cached source for entire application). IEnumerable <UserProfile> userProfiles = new List <UserProfile>(); CarEditViewModel carEditViewModel = new CarEditViewModel(id, carDataService, userProfiles); this.DataContext = carEditViewModel; }
public IActionResult Edit(int id, [FromServices] ICarsService carsService) { CarEditViewModel model = carsService.GetEditViewModel(id); if (model != null) { return(this.PartialView("_EditModal", model)); } return(this.RedirectToAction("Error", "Home")); }
public async Task EditCarAsync(CarEditViewModel car) { var wantedCar = this.db.Cars.FirstOrDefault(x => x.Id == car.Id); wantedCar.Contact = car.Contact; wantedCar.ImageUrl = car.Image; wantedCar.Info = car.Info; wantedCar.Model = car.Model; wantedCar.Price = car.Price; wantedCar.Year = car.Year; await this.db.SaveChangesAsync(); }
public ViewResult EditCar(int id) { Car car = _repository.Select <Car>().Include(c => c.Owners).FirstOrDefault(c => c.Id == id); List <Owner> owners = _repository.Select <Owner>().ToList(); CarEditViewModel model = new CarEditViewModel { Car = car, Owners = owners }; return(View(model)); }
public IActionResult Edit(int id) { Car car = carRepository.GetCarByID(id); CarEditViewModel model = new CarEditViewModel { Drivers = GetDrivers(), CarID = car.CarID, Manufacturer = car.Manufacturer, MOT = car.MOT }; return(View(model)); }
public async Task <IActionResult> Edit([FromBody] CarEditViewModel model) { if (ModelState.IsValid) { CommandResult <Car> result = await _mediator.Send(new UpdateEntityCommand <Car>(_mapper.Map <Car>(model))); if (result.Result == CommandState.Success) { return(Ok(model)); } } return(StatusCode(StatusCodes.Status500InternalServerError, "An error has occured")); }
public ActionResult editVehicle(int id) { ModelMockRepo modelRepo = new ModelMockRepo(); MakeMockRepo makeRepo = new MakeMockRepo(); CarMockRepository carRepo = new CarMockRepository(); CarEditViewModel vm = new CarEditViewModel(); vm.Car = carRepo.GetById(id); vm.Car.Make = makeRepo.GetById(vm.Car.MakeId); vm.Car.Model = modelRepo.GetById(vm.Car.ModelId); vm.Makes = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName"); vm.Models = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName"); return(View(vm)); }
public ActionResult Edit(CarEditViewModel model) { if (ModelState.IsValid) { var carRepo = GuildRepositoryFactory.GetRepository(); carRepo.UpdateCar(model.Car); return(RedirectToAction("Vehicles")); } else { return(View(model.Car)); } }
public async Task <IActionResult> Edit(CarEditViewModel input) { if (!this.ModelState.IsValid) { var makesAndColors = this.carsService.GetAllMakesAndColors(); var viewModel = input; viewModel.Makes = makesAndColors.Makes; viewModel.Colors = makesAndColors.Colors; return(this.View(viewModel)); } await this.carsService.Update(input); return(this.Redirect("/Home/MyCars")); }
public ViewResult Edit(int id) { Car car = _carRepository.GetCarById(id); CarEditViewModel carEditViewModel = new CarEditViewModel { Id = car.Id, CarName = car.CarName, VehicleClass = car.VehicleClass, Capacity = car.Capacity, CarType = car.CarType, Price = car.Price, ExistingPhotoPath = car.PhotoPath }; return(View(carEditViewModel)); }
private static CarEditViewModel ConvertCar(Car car) { var vm = new CarEditViewModel { Id = car.Id, Color = car.Color, Buydate = car.Buydate, Plate = car.Plate, Owner = car.Owner?.FullName, OwnerId = car.Owner?.Id, Cartype = car.Cartype?.FullType, CartypeId = car.Cartype?.Id, }; return(vm); }
public ActionResult Edit(int id) { var carViewModel = new CarEditViewModel(); var carRepo = GuildRepositoryFactory.GetRepository(); var makesRepo = MakeFactory.GetRepository(); var modelRepo = ModelFactory.GetRepository(); var typesRepo = ConditionFactory.GetRepository(); var bodyStylesRepo = BodyStyleFactory.GetRepository(); var transmissionsRepo = TransmissionFactory.GetRepository(); var extColorsRepo = ExteriorColorFactory.GetRepository(); var intColorsRepo = InteriorColorFactory.GetRepository(); var carvm = carRepo.GetCarById(id); carViewModel.CarID = carvm.CarID; carViewModel.Year = carvm.Year; carViewModel.Make = new Make(); carViewModel.Makes = makesRepo.GetMakes(); carViewModel.MakesID = carvm.MakeID; carViewModel.Model = new Model(); carViewModel.Models = modelRepo.GetModels(); carViewModel.ModelsID = carvm.ModelID; carViewModel.Condition = new Condition(); carViewModel.ConditionTypes = typesRepo.GetConditions(); carViewModel.ConditionTypesID = carvm.ConditionID; carViewModel.BodyStyle = new BodyStyle(); carViewModel.BodyStyles = bodyStylesRepo.GetBodyStyles(); carViewModel.BodyStylesID = carvm.BodyStyleID; carViewModel.Transmission = new Transmission(); carViewModel.Transmissions = transmissionsRepo.GetTransmissions(); carViewModel.TransmissionsID = carvm.TransmissionID; carViewModel.ExteriorColor = new ExteriorColor(); carViewModel.ExteriorColors = extColorsRepo.GetExteriorColors(); carViewModel.ExteriorColorsID = carvm.ExteriorColorID; carViewModel.InteriorColor = new InteriorColor(); carViewModel.InteriorColors = intColorsRepo.GetInteriorColors(); carViewModel.InteriorColorsID = carvm.InteriorColorID; carViewModel.Mileage = carvm.Mileage; carViewModel.VIN = carvm.VIN; carViewModel.SalePrice = carvm.SalePrice; carViewModel.MSRP = carvm.MSRP; carViewModel.ImageFileName = carvm.Photo; carViewModel.Description = carvm.Description; return(View(carViewModel)); }