public SearchViewModel GetPreapreSearchModel() { var locations = _locationBusiness.GetNames(); var locationViewModels = Mapper.Map <List <LocationSearchModel>, List <LocationViewModel> >(locations); var vehicleTypes = _vehicleTypeBusiness.GetAll(false); var vehicleTypeViewModels = new List <VehicleTypeViewModel>(); foreach (var item in vehicleTypes) { var viewModelItem = new VehicleTypeViewModel { Id = item.Id, Name = item.Name, Path = item.Image.Path }; vehicleTypeViewModels.Add(viewModelItem); } var model = new SearchViewModel { DateFrom = DateTime.Now, DateTo = DateTime.Now.AddDays(1), Locations = locationViewModels, LocationId = 0, VehicleTypes = vehicleTypeViewModels, VehicleTypeId = 0 }; return(model); }
public JsonResult GetVehicleTypes(VehicleTypeViewModel vtViewModel) { PaginationInfo pager = new PaginationInfo(); pager = vtViewModel.Pager; PaginationViewModel pViewModel = new PaginationViewModel(); try { pViewModel.dt = _vtRepo.GetVehicleTypes(vtViewModel.VehicleType.VehicleTypeName, ref pager); pViewModel.Pager = pager; Logger.Debug("VehicleType Controller GetVehicleBrands"); } catch (Exception ex) { vtViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01")); Logger.Error("VehicleType Controller - GetVehicleBrands" + ex.ToString()); } return(Json(JsonConvert.SerializeObject(pViewModel), JsonRequestBehavior.AllowGet)); }
private VehicleTypeDTO Create(VehicleTypeViewModel viewModel) { try { log.Debug(VehicleTypeViewModel.FormatVehicleTypeViewModel(viewModel)); VehicleTypeDTO vehicleType = new VehicleTypeDTO(); // copy values viewModel.UpdateDTO(vehicleType, null); //RequestContext.Principal.Identity.GetUserId()); // audit vehicleType.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); vehicleType.CreateOn = DateTime.UtcNow; // add log.Debug("_vehicleTypeService.AddVehicleType - " + VehicleTypeDTO.FormatVehicleTypeDTO(vehicleType)); int id = _vehicleTypeService.AddVehicleType(vehicleType); vehicleType.VehicleTypeId = id; log.Debug("result: 'success', id: " + id); return(vehicleType); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
public ActionResult Create([Bind(Include = "Id,Name")] VehicleTypeViewModel vehicleTypeViewModel) { try { if (ModelState.IsValid) { VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel); var name = vehicleType.Name.Trim(); if (_vehicleTypeManager.GetAll().Count(o => o.Name == name) > 0) { ViewBag.Message = "Vehicle type name already exist."; } if (ViewBag.Message == null) { _vehicleTypeManager.Add(vehicleType); TempData["msg"] = "Information has been saved successfully"; return(RedirectToAction("Index")); } } return(View(vehicleTypeViewModel)); } catch (Exception ex) { ExceptionMessage(ex); return(View("Error", new HandleErrorInfo(ex, "VehicleTypes", "Create"))); } }
public IHttpActionResult Get(int id) { try { // get log.Debug("_vehicleTypeService.GetVehicleType - vehicleTypeId: " + id + " "); var vehicleType = new VehicleTypeViewModel(_vehicleTypeService.GetVehicleType(id)); log.Debug("_vehicleTypeService.GetVehicleType - " + VehicleTypeViewModel.FormatVehicleTypeViewModel(vehicleType)); log.Debug("result: 'success'"); //return Json(vehicleType, JsonRequestBehavior.AllowGet); //return Content(JsonConvert.SerializeObject(vehicleType), "application/json"); //return vehicleType; //return JsonConvert.SerializeObject(vehicleType); return(Ok(vehicleType)); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
public ActionResult Create(VehicleTypeViewModel collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var vehicletype = _mapper.Map <VehicleType>(collection); var IsSuccess = _vehicleTypeManager.Add(vehicletype); if (IsSuccess) { return(RedirectToAction("Index")); } return(NotFound()); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
// GET: VehicleType/Create public ActionResult Create() { var model = new VehicleTypeViewModel(); model.vehicleCollection = _vehicleTypeManager.GetAll(); return(View(model)); }
public async Task <IHttpActionResult> Get(int id) { var selectedVehicleType = await _vehicleTypeApplicationService.GetAsync(id); VehicleTypeViewModel vehicleType = Mapper.Map <VehicleTypeViewModel>(selectedVehicleType); return(Ok(vehicleType)); }
// GET: AdminPanel/VehicleType/Create public ActionResult Create() { var model = new VehicleTypeViewModel(); var image = new ImageViewModel(); model.Image = image; return(View("Modify", model)); }
public static VehicleType ToModel(this VehicleTypeViewModel vm, VehicleType model = null) { if (model == null) { model = new VehicleType(); } model.Name = vm.Name; model.EngineOilChangeMilage = vm.EngineOilChangeMilage; model.FuelFilterChangeMilage = vm.FuelFilterChangeMilage; model.GearBoxChangeMilage = vm.GearBoxChangeMilage; model.HasDifferentialOil = vm.HasDifferentialOil; if (vm.HasDifferentialOil) { model.DifferentialOilChangeMilage = vm.DifferentialOilChangeMilage; model.DifferentialOilId = vm.DifferentialOilId > 0 ? vm.DifferentialOilId : (int?)null; } else { model.DifferentialOilChangeMilage = (int?)null; model.DifferentialOilId = (int?)null; } model.FuelFilterNumber = vm.FuelFilterNumber; model.AirCleanerMilage = vm.AirCleanerAge; if (vm.HasGreeceNipple) { model.GreeceNipleAge = vm.GreeceNipleAge; } else { model.GreeceNipleAge = (int?)null; } model.InsuranceAge = vm.InsuranceAge; model.HasFitnessReport = vm.HasFitnessReport; if (vm.HasFitnessReport) { model.FitnessReportAge = vm.FitnessReportAge; } else { model.FitnessReportAge = (int?)null; } model.EmitionTestAge = vm.EmitionTestAge; model.RevenueLicenceAge = vm.RevenueLicenceAge; model.FuelType = vm.FuelType; model.BreakOilId = vm.EngineOilId > 0 ? vm.BreakOilId : (int?)null; model.EngineCoolantId = vm.EngineCoolantId > 0 ? vm.EngineCoolantId : (int?)null; model.EngineOilId = vm.EngineOilId > 0 ? vm.EngineOilId : (int?)null; model.GearBoxOilId = vm.GearBoxOilId > 0 ? vm.GearBoxOilId : (int?)null; model.PowerSteeringOilId = vm.PowerSteeringOilId > 0 ? vm.PowerSteeringOilId : (int?)null; return(model); }
public IActionResult CreateType(VehicleTypeViewModel type) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <VehicleTypeViewModel, VehicleTypeDto>()).CreateMapper(); var typeDto = mapper.Map <VehicleTypeViewModel, VehicleTypeDto>(type); db.Create(typeDto); return(RedirectToAction("ViewVehicleTypes")); }
public IActionResult New() { var viewModel = new VehicleTypeViewModel(new VehicleType()) { Statuses = _context.Statuses.ToList() }; return(View("VehicleForm", viewModel)); }
public async Task <IActionResult> Details(int id) { var returnUrl = Request.Headers["Referer"].ToString(); var vehicleType = await _vehicleTypeRepo.GetVehicleType(id); VehicleTypeViewModel vehicleTypeVM = VehicleTypeViewModelFactory.Details(vehicleType, returnUrl); return(View("Edit", vehicleTypeVM)); }
public async Task <ResponseViewModel> SaveVehicleType(VehicleTypeViewModel vm) { var response = new ResponseViewModel(); try { var model = _db.VehicleTypes.FirstOrDefault(t => t.Id == vm.Id); if (model == null) { model = vm.ToModel(); _db.VehicleTypes.Add(model); await _db.SaveChangesAsync(); response.IsSuccess = true; response.Message = "New Vehicle type has been added."; } else { model.Name = vm.Name; model.EngineOilChangeMilage = vm.EngineOilChangeMilage; model.FuelFilterChangeMilage = vm.FuelFilterChangeMilage; model.GearBoxChangeMilage = vm.GearBoxChangeMilage; model.DifferentialOilChangeMilage = vm.DifferentialOilChangeMilage; model.FuelFilterNumber = vm.FuelFilterNumber; model.AirCleanerMilage = vm.AirCleanerAge; model.GreeceNipleAge = vm.GreeceNipleAge; model.InsuranceAge = vm.InsuranceAge; model.FitnessReportAge = vm.FitnessReportAge; model.EmitionTestAge = vm.EmitionTestAge; model.RevenueLicenceAge = vm.RevenueLicenceAge; model.FuelType = vm.FuelType; model.EngineOilId = vm.EngineOilId > 0 ? vm.EngineOilId : (int?)null; model.GearBoxOilId = vm.GearBoxOilId > 0 ? vm.GearBoxOilId : (int?)null; model.DifferentialOilId = vm.DifferentialOilId > 0 ? vm.DifferentialOilId : (int?)null; model.BreakOilId = vm.BreakOilId > 0 ? vm.BreakOilId : (int?)null; model.EngineCoolantId = vm.EngineCoolantId > 0 ? vm.EngineCoolantId : (int?)null; model.PowerSteeringOilId = vm.PowerSteeringOilId > 0 ? vm.PowerSteeringOilId : (int?)null; _db.VehicleTypes.Update(model); await _db.SaveChangesAsync(); response.IsSuccess = true; response.Message = "Vehicle type has been updated."; } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Operation failed.Please try again."; } return(response); }
public ActionResult Edit([Bind(Include = "Id,Name")] VehicleTypeViewModel vehicleTypeViewModel) { if (ModelState.IsValid) { VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel); db.Entry(vehicleType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vehicleTypeViewModel)); }
public async Task <IActionResult> Delete(VehicleTypeViewModel vehicleTypeVM) { await _vehicleTypeRepo.DeleteVehicleType(vehicleTypeVM.VehicleType); TempData["message"] = "Your data has been deleted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(Redirect(vehicleTypeVM.ReturnUrl)); }
// GET: ParkedVehicles // STEFAN start public async Task <IActionResult> Index() { var vehicles = await _context.ParkedVehicle.Include(p => p.VehicleType).ToListAsync(); var model = new VehicleTypeViewModel { VehicleList = vehicles, VehicleTypes = await GetTypeAsync() }; return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,TypeName,Description")] VehicleTypeViewModel vehicleTypeViewModel) { if (ModelState.IsValid) { VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel); _vehicleTypeManager.Update(vehicleType); TempData["Message"] = "Vehicle Type info save successfully!"; return(RedirectToAction("Index")); } return(View(vehicleTypeViewModel)); }
public async Task <ActionResult> Create([Bind(include: "TypeName,TaxCoefficient")] VehicleTypeViewModel model) { if (ModelState.IsValid) { var type = mapper.Map <VehicleTypeDto>(model); await vehicleTypeService.Create(type); } else { return(View()); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id, string returnUrl = null) { if (String.IsNullOrEmpty(returnUrl)) { returnUrl = Request.Headers["Referer"].ToString(); } var vehicleType = await _vehicleTypeRepo.GetVehicleType(id); VehicleTypeViewModel vehicleTypeVM = VehicleTypeViewModelFactory.Edit(vehicleType, returnUrl); return(View("Edit", vehicleTypeVM)); }
public ActionResult Create(VehicleTypeViewModel model) { if (ModelState.IsValid) { VehicleType vehicleType = new VehicleType() { FareRate = model.FareRate, Name = model.Name }; _vehicleTypeRepository.Add(vehicleType); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create([Bind(Include = "Id,Name")] VehicleTypeViewModel vehicleTypeViewModel) { if (ModelState.IsValid) { VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel); db.VehicleTypes.Add(vehicleType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vehicleTypeViewModel)); }
public ActionResult Edit(VehicleTypeViewModel model) { if (ModelState.IsValid) { VehicleType vehicleType = new VehicleType() { Name = model.Name, FareRate = model.FareRate, Id = model.Id }; _vehicleTypeRepository.Update(vehicleType); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult EditType(VehicleTypeViewModel type) { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <VehicleTypeViewModel, VehicleTypeDto>()).CreateMapper(); var typeDto = mapper.Map <VehicleTypeViewModel, VehicleTypeDto>(type); db.Update(typeDto); return(RedirectToAction("ViewVehicleTypes")); } else { return(RedirectToAction("EditType")); } }
// GET: VehicleType/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(HttpNotFound()); } VehicleType vehicleType = _typeManager.GetById((int)id); VehicleTypeViewModel vehicleTypeVM = new VehicleTypeViewModel() { Id = vehicleType.Id, TypeName = vehicleType.TypeName }; return(View(vehicleTypeVM)); }
// GET: VehicleTypes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VehicleType vehicleType = _vehicleTypeManager.GetById((int)id); if (vehicleType == null) { return(HttpNotFound()); } VehicleTypeViewModel vehicleTypeViewModel = Mapper.Map <VehicleTypeViewModel>(vehicleType); return(View(vehicleTypeViewModel)); }
public IActionResult Edit(int id) { var vehicleType = _context.VehicleTypes.SingleOrDefault(vt => vt.Id == id); if (vehicleType == null) { return(NotFound()); } var viewModel = new VehicleTypeViewModel(vehicleType) { Statuses = _context.Statuses.ToList(), }; return(View("VehicleForm", viewModel)); }
public ActionResult Edit(VehicleTypeViewModel vehicleTypeVM) { try { VehicleType vehicleType = new VehicleType() { Id = vehicleTypeVM.Id, TypeName = vehicleTypeVM.TypeName }; _typeManager.Update(vehicleType); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: /VehicleType/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VehicleType vehicletype = db.VehicleTypes.Find(id); if (vehicletype == null) { return(HttpNotFound()); } VehicleTypeViewModel vehicleTypeViewModel = Mapper.Map <VehicleTypeViewModel>(vehicletype); return(View(vehicleTypeViewModel)); }
public async Task <IActionResult> Filter(VehicleTypeViewModel viewModel) { var vehicles = string.IsNullOrWhiteSpace(viewModel.SearchString) ? _context.ParkedVehicle : _context.ParkedVehicle.Where(m => m.RegNum.Contains(viewModel.SearchString)); vehicles = viewModel.VehicleType == null ? vehicles : vehicles.Where(m => m.VehicleType == viewModel.VehicleType); var model = new VehicleTypeViewModel { VehicleList = await vehicles.ToListAsync(), VehicleTypes = await TypeAsync() }; return(View(nameof(Index), model)); }