public ActionResult VehicleInfo(VehicleVM vehicleVM) { if (Session["Tracker"] == null) { return(RedirectToAction("ApplicantInfo", "Applicant")); } var tracker = (Guid)Session["Tracker"]; if (ModelState.IsValid) { var applicant = _applicantService.GetApplicantsByTraker(tracker); var existingVehicle = applicant.Vehicle.FirstOrDefault(); if (existingVehicle != null) { var vehicleDto = Mapper.Map(vehicleVM, existingVehicle); _vehicleService.Update(vehicleDto); } else { var vehicle = Mapper.Map(vehicleVM, existingVehicle); applicant.Vehicle.Add(vehicle); } return(RedirectToAction("ProductInfo", "Products")); } return(View()); }
public async Task <IActionResult> Update(VehicleVM vehicleVM, AppUserVM appUserVM, CustomerVM customerVM, string makeName, string modelName) { vehicleVM.MakeVM = new MakeVM { Name = makeName }; vehicleVM.ModelVM = new ModelVM { Name = modelName }; var vehicleModelMVC = new VehicleModelMVC { Id = vehicleVM.Id, CreateAt = vehicleVM.CreateAt, CustomerVM = customerVM, MakeVM = vehicleVM.MakeVM, ModelVM = vehicleVM.ModelVM, AppUserVM = appUserVM, Odometer = vehicleVM.Odometer, VIN = vehicleVM.VIN, Engine = vehicleVM.Engine }; string token = HttpContext.Session.GetString("token_access"); return(View(await listChosen(token, vehicleModelMVC))); }
public ActionResult Edit(int carId, int makeId, int modelId) { var editCar = Factory.Create().GetById(carId); var model = new VehicleVM() { CarID = editCar.CarID, BodyStyle = editCar.BodyStyle, CarDescription = editCar.CarDescription, CarType = editCar.CarType, CarYear = editCar.CarYear, Color = editCar.Color, Interior = editCar.Interior, Mileage = editCar.Mileage, MSRP = editCar.MSRP, SalePrice = editCar.SalePrice, Trans = editCar.Trans, Vin = editCar.Vin, IsFeatured = editCar.IsFeatured, }; model.MakesDropDown = new SelectList(Factory.MakeRepo().Get(), nameof(Make.MakeID), nameof(Make.MakeName)); model.ModelsDropDown = new SelectList(Factory.ModelRepo().Get(), nameof(Model.ModelID), nameof(Model.ModelName)); return(View(model)); }
public ActionResult Add(VehicleVM model) { if (ModelState.IsValid) { Vehicle newVehicle = new Vehicle(); { newVehicle.BodyStyleId = model.BodyStyleId; newVehicle.VehicleModelId = model.VehicleModelId; newVehicle.VehicleMakeId = model.VehicleMakeId; newVehicle.ExteriorColorId = model.ExteriorColorId; newVehicle.InteriorColorId = model.InteriorColorId; newVehicle.Transmission = model.Transmission; newVehicle.Feature = model.Feature; if (ModelState.IsValid) { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { string path = Path.Combine(Server.MapPath("~/Content/img"), Path.GetFileName(model.ImageUpload.FileName)); model.ImageUpload.SaveAs(path); } } newVehicle.Image = model.Image; newVehicle.Mileage = model.Mileage; newVehicle.MSRP = model.MSRP; newVehicle.New = model.New; newVehicle.SalePrice = model.SalePrice; newVehicle.VIN = model.VIN; newVehicle.Year = model.Year; } _repo.AddVehicle(newVehicle); } return(RedirectToAction("Admin")); }
public async Task <Response> RemoveVehicle(VehicleVM vehicle) { try { var vehicleDTO = await _db.vehicles.Where(x => x.Id == vehicle.Id).FirstOrDefaultAsync(); _db.vehicles.Remove(vehicleDTO); int result = await _db.SaveChangesAsync(); if (result == 1) { // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result)); } else { return(GenericResponses <int> .ResponseStatus(true, Constant.MSGFailed, (int)Constant.httpStatus.NoContent, result)); } } catch (Exception e) { return(GenericResponses <int> .ResponseStatus(true, e.Message, (int)Constant.httpStatus.NoContent, 0)); } }
public async Task <Response> AddVehicle(VehicleVM vehicle) { var vehicleDto = Mapper.Map <VehicleVM, vehicle>(vehicle); vehicle vehicleExist = await _db.vehicles.Where(x => x.RegNumber.Trim() == vehicle.RegNumber.Trim()).FirstOrDefaultAsync(); if (vehicleExist != null) { return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoAlreadyExist, (int)Constant.httpStatus.NoContent, 0)); } _db.vehicles.Add(vehicleDto); int result = await _db.SaveChangesAsync(); if (result == 1) { // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result)); } else { return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoLoginFailed, (int)Constant.httpStatus.NoContent, result)); } }
public List <VehicleVM> GetVehicleByType(VehicleVM entitie) { var filterVehicle = _vehicleRepo.GetAll().Where(v => v.Type == entitie.Type).ToList(); var vms = Mapper.MapVehicleModelsToVehicleVM(filterVehicle); return(vms); }
public IActionResult GetByNumber(ApiRequest vehicle) { try { VehicleVM rbVehicles = (from v in dbContext.Vehicles join d in dbContext.Drivers on v.VehicleNumber equals d.VehicleNumber where v.VehicleNumber == vehicle.VehicleNumber select new VehicleVM() { VehicleId = v.Id, Active = v.Active, DriverName = d.Name, IMEI = v.IMEI, Region = v.Region, SIM = v.SIM, SubRegion = v.SubRegion, Station = v.Station, VehicleNumber = v.VehicleNumber, Type = v.Status, GasolineType = v.GasolineType, CardNumber = v.CardNumber, PeriodicRemarks = v.PeriodicStatus == Shared.Enums.PeriodicMaintenanceStatus.Done ? "Periodically Maintained" : "Periodic Maintenance Pending", AccidentalStatus = v.AccidentalStatus, EmergencyStatus = v.EmergencyStatus, PeriodicStatus = v.PeriodicStatus }).SingleOrDefault(); return(Ok(rbVehicles)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> RegVehicle(Vehicle vehicle) { if (ModelState.IsValid) { using (var client = new HttpClient()) { try { vehicle.Deleted = 0; vehicle.WriteHistory = 0; String _result = await VehicleVM.InsertVehicleAsync(client, vehicle); if (_result.Equals(ResultCode.DONE)) { return(RedirectToAction("RegVehicle", "Home")); } else { return(BadRequest(Lang.LANG_SELECT_PROBLEM)); } } catch (Exception) { return(BadRequest(Lang.LANG_CONNECTION_PROBLEM)); } } } return(View()); }
public ActionResult AddVehicle(VehicleVM m) { if (ModelState.IsValid) { var newCar = new Car { CarYear = m.Year, Exterior = m.Color, Interior = m.Interior, Sold = null, IsNew = m.IsNew, IsFeatured = false, IsManual = !m.IsAutomatic, Mileage = m.Mileage, MSRP = m.MSRP, Price = m.Price, VIN = m.VIN, Model = new CarModel { ModelId = m.Model.ModelId }, }; repo.AddCar(newCar); return(RedirectToAction("Index")); } m.PopulateMakeList(repo); m.PopulateModelList(repo); m.PopulateStyleList(repo); return(View(m)); }
public ActionResult VehicleInfo(VehicleVM vm) { if (Session["Tracker"] == null) { return(RedirectToAction("ApplicantInfo", "Applicant")); } var tracker = (Guid)Session["Tracker"]; if (ModelState.IsValid) { var applicant = _context.Applicants.FirstOrDefault(x => x.ApplicantTracker == tracker); var existingVehicle = applicant.Vehicle.FirstOrDefault(); if (existingVehicle != null) { Mapper.Map(vm, existingVehicle); _context.Entry(existingVehicle).State = EntityState.Modified; } else { var vehicle = Mapper.Map <Vehicle>(vm); applicant.Vehicle.Add(vehicle); } _context.SaveChanges(); return(RedirectToAction("ProductInfo", "Products")); } return(View()); }
public async Task <ActionResult <Vehicle> > PostVehicle(VehicleVM vehicle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newvehicle = new Vehicle { ModelId = vehicle.ModelId, Model = _context.Models.FirstOrDefault(m => m.Id == vehicle.ModelId), IsRegistered = vehicle.IsRegistered, ContactName = vehicle.ContactName, ContactPhone = vehicle.ContactPhone, ContactEmail = vehicle.ContactEmail, MoreInfo = vehicle.MoreInfo, LastUpdated = DateTime.UtcNow }; newvehicle.VehicleFeatures = vehicle.VehicleFeatures.Select(f => new VehicleFeature { FeatureId = f, VehicleId = newvehicle.Id }).ToList(); _context.Vehicle.Add(newvehicle); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVehicle", new { id = newvehicle.Id }, newvehicle)); }
public async Task <IActionResult> Edit(Vehicle vehicle) { if (ModelState.IsValid) { using (var client = new HttpClient()) { try { String _result = await VehicleVM.UpdateVehicleAsync(client, vehicle); if (_result.Equals(ResultCode.DONE)) { return(RedirectToAction("Index")); } else { return(BadRequest(Lang.LANG_UPDATE_PROBLEM)); } } catch (Exception) { return(BadRequest(Lang.LANG_CONNECTION_PROBLEM)); } } } return(View()); }
public async Task <JsonResult> RemoveVehicle(VehicleVM vehicle) { vehicle.EcomID = (int)Session["Comp"]; vehicle.CreatedOn = DateTime.Today; Response r = await Repository.RemoveVehicle(vehicle); // List<UserVM> employees = ((IEnumerable)r.Value).Cast<UserVM>().ToList(); ; return(Json(r, JsonRequestBehavior.AllowGet)); }
async public Task <ActionResult> New(VehicleVM vehicleVM) { vehicleVM.Vehicle.VehicleStatusId = 2; Db.VehicleRecords.Add(vehicleVM.Vehicle); await Db.SaveChangesAsync(); return(RedirectToAction("ViewAll")); }
public ActionResult AddVehicle() { VehicleVM viewToPass = new VehicleVM(); viewToPass.PopulateMakeList(repo); viewToPass.PopulateModelList(repo); viewToPass.PopulateStyleList(repo); return(View(viewToPass)); }
public ActionResult Add() { var model = new VehicleVM(); model.MakesDropDown = new SelectList(Factory.MakeRepo().Get(), nameof(Make.MakeID), nameof(Make.MakeName)); model.ModelsDropDown = new SelectList(Factory.ModelRepo().Get(), nameof(Model.ModelID), nameof(Model.ModelName)); return(View(model)); }
private void GetAllDealers() { JObject allVehicleIDs; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://vautointerview.azurewebsites.net/api/"); var responseTask = client.GetAsync(VHelper.datasetId + "/vehicles"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readtask = result.Content.ReadAsAsync <JObject>(); readtask.Wait(); allVehicleIDs = readtask.Result; VHelper.arrOfIds = (JArray)allVehicleIDs["vehicleIds"]; VehicleVM tempV = null; DealerVM tempD = null; foreach (int jobj in VHelper.arrOfIds) { tempV = VHelper.vehicles.ContainsKey(jobj) ? VHelper.vehicles[jobj] : GetSingleVehicle(client, jobj); tempD = GetSingleDealer(client, tempV.dealerId); tempD.vehicles = new List <VehicleVM>() { tempV }; if (VHelper.dealers.ContainsKey(tempD.dealerId)) { //tempD.vehicles.AddRange(VHelper.dealers[tempD.dealerId].vehicles); if (!VHelper.dealers[tempD.dealerId].vehicles.Contains(tempV)) { VHelper.dealers[tempD.dealerId].vehicles.Add(tempV); } //VHelper.dealers.Remove(tempD.dealerId); } else { VHelper.dealers.Add(tempD.dealerId, tempD); } } } else { allVehicleIDs = null; throw new Exception("Server error. Please contact administrator."); } } }
// GET: Vehicle async public Task <ActionResult> New() { var vehicleTypes = await Db.VehicleTypes.ToListAsync(); var vehicleVM = new VehicleVM() { VehicleTypes = vehicleTypes }; return(View(vehicleVM)); }
/// <summary> /// constructor /// </summary> /// <param name="data">data view model</param> public VehiclesVM(Data data) { this.data = data; foreach (var vehicle in data.Vehicles) { var vehicleVM = new VehicleVM(vehicle); VehicleVMs.Add(vehicleVM); } VehicleVMs.CollectionChanged += VehicleVMs_CollectionChanged; }
public async Task <ApiResultVM <string> > Update(VehicleVM vehicleVM, string token) { var client = _httpClientFactory.CreateClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); client.BaseAddress = new Uri(_configuration["UrlApi"]); var response = await client.PutAsJsonAsync("/api/vehicles/" + vehicleVM.Id, vehicleVM); var body = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ApiResultVM <string> >(body)); }
public ActionResult Add() { var model = new VehicleVM(); model.SetMakes(_repo.GetAllMakes()); model.SetModels(_repo.GetAllModels()); model.SetStyles(_repo.GetAllStyles()); model.SetInterior(_repo.GetAllInterior()); model.SetExterior(_repo.GetAllExterior()); model.SetTypes(_repo.GetAllTypes()); return(View(model)); }
public ActionResult VehicleInfo() { var tracker = (Guid)Session["Tracker"]; var vehicle = new VehicleVM(); var existingVehicle = _applicantService.GetApplicantsByTraker(tracker)?.Vehicle.FirstOrDefault(); if (existingVehicle != null) { vehicle = Mapper.Map <VehicleVM>(existingVehicle); } return(View(vehicle)); }
public async Task <JsonResult> AddVehicle(VehicleVM vehicle) { vehicle.CreatedOn = DateTime.Today; vehicle.EcomID = (int)Session["Comp"]; if (((bool)vehicle.IsContractorVehicle) == false) { vehicle.ContractorId = null; } Response r = await Repository.AddVehicle(vehicle); // List<UserVM> employees = ((IEnumerable)r.Value).Cast<UserVM>().ToList(); ; return(Json(r, JsonRequestBehavior.AllowGet)); }
public async Task <ApiResultVM <string> > Update(VehicleVM vehicleVM, int id) { var checkValue = await GetById(id); var customerDTO = await _dbContextDTO.customerDTOs.Where(x => (x.FirstName + x.LastName).Equals(vehicleVM.CustomerVM.FirstName + vehicleVM.CustomerVM.LastName)).AsNoTracking().SingleOrDefaultAsync(); var makeDTO = await _dbContextDTO.makeDTOs.Where(x => x.Name.Equals(vehicleVM.MakeVM.Name)).AsNoTracking().SingleOrDefaultAsync(); var modelDTO = await _dbContextDTO.modelDTOs.Where(x => x.Name.Equals(vehicleVM.ModelVM.Name)).AsNoTracking().SingleOrDefaultAsync(); var userDTO = await _dbContextDTO.appUserDTOs.Where(x => x.FullName.Equals(vehicleVM.AppUserVM.FullName)).AsNoTracking().SingleOrDefaultAsync(); if (checkValue == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Vehicle doesn't exist")); } if (customerDTO == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Customer doesn't exist")); } if (makeDTO == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Make doesn't exist")); } if (modelDTO == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Model doesn't exist")); } if (userDTO == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Users doesn't exist")); } vehicleVM.CustomerId = customerDTO.Id; vehicleVM.MakeId = makeDTO.Id; vehicleVM.ModelId = modelDTO.Id; vehicleVM.AppUserId = userDTO.Id; var vehicleDTO = _mapper.Map <VehicleDTO>(vehicleVM); vehicleDTO.Id = id; vehicleDTO.UpdateAt = DateTime.Now; dbset.Update(vehicleDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Update Success")); }
public async Task <Response> GetallVehicles() { try { List <VehicleVM> response = new List <VehicleVM>(); //var users = _db.Users.Select(x => x).ToList(); var vehiclesDTO = await _db.vehicles.ToListAsync(); // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); // response = Mapper.Map<IEnumerable<GoodsType>, List<GoodsTypeVM>>(goods); foreach (var vehicle in vehiclesDTO) { VehicleVM obj = new VehicleVM(); obj.Capacity = vehicle.Capacity; obj.CreatedOn = vehicle.CreatedOn; obj.EcomID = vehicle.EcomID; obj.Id = vehicle.Id; obj.Manufacturer = vehicle.Manufacturer; obj.Model = vehicle.Model; obj.RegNumber = vehicle.RegNumber; obj.Status = vehicle.Status; obj.StatusName = _shareRepo.GetVehicleStatusByID((int)vehicle.Status); obj.Type = vehicle.Type; obj.TypeName = _shareRepo.GetVehicleTypeID((int)vehicle.Type); obj.Unit = vehicle.Unit; obj.UnitName = _shareRepo.GetUnitByID((int)vehicle.Unit); obj.IsContractorVehicle = vehicle.IsContractorVehicle; obj.ContractorId = vehicle.ContractorId; response.Add(obj); } if (response.Count() > 0) { return(GenericResponses <IEnumerable <VehicleVM> > .ResponseStatus(false, response.Count() + Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, response)); } else { return(GenericResponses <IEnumerable <VehicleVM> > .ResponseStatus(false, Constant.MDGNoRecordFound, (int)Constant.httpStatus.NoContent, response.ToList())); } } catch (Exception e) { return(GenericResponses <VehicleVM> .ResponseStatus(true)); } }
public JsonResult Insert_VehicleMaster(VehicleVM VehicleVM) { bool result = false; string msg = "Failed to save record.."; msg = VehicleMethods.Insert_VehicleMaster(VehicleVM, Session["DealerCode"].ToString(), ref msg); if (msg == "Completed") { result = true; } return(Json(new { Success = result, Message = msg }, JsonRequestBehavior.AllowGet)); }
public VehicleVM getVehicleById(int Id) { var entity = _dbcontext.Vehicles.Find(Id); VehicleVM model = new VehicleVM(); if (entity != null) { model.LicencePlate = entity.LicensePlate; model.Make = entity.Make; model.RegistrationDate = entity.RegistrationDate; model.ChassisNo = entity.ChassisNo; model.OwnerId = entity.OwnerId; } return(model); }
public string updateVehicle(VehicleVM model) { var entity = _dbcontext.Vehicles.Find(model.Id); if (entity != null) { entity.LicensePlate = model.LicencePlate; entity.Make = model.Make; entity.RegistrationDate = model.RegistrationDate; entity.ChassisNo = model.ChassisNo; entity.OwnerId = model.OwnerId; _dbcontext.SaveChanges(); } return(entity.ToString()); }
public ActionResult Edit(int id) { //var vehicle = _repo.GetVehicleById(id); var model = new VehicleVM(); model.SetMakes(_repo.GetAllMakes()); model.SetModels(_repo.GetAllModels()); model.SetStyles(_repo.GetAllStyles()); model.SetInterior(_repo.GetAllInterior()); model.SetExterior(_repo.GetAllExterior()); model.SetTypes(_repo.GetAllTypes()); model.Vehicle = _repo.GetVehicleById(id); return(View(model)); }