public void Edit_ShouldEditItem( int id, string chassis, EnumModelViewModel model, int year, int modelYear) { // Arrange var truckViewModel = new TruckViewModel { Id = id, Chassis = chassis, Model = model, Year = year, ModelYear = modelYear }; // Act var result = Controller.Edit(id, truckViewModel) as RedirectToActionResult; var truck = FakeUnitOfWork.TruckRepository.GetAll(t => t.Chassis.Equals(chassis)).FirstOrDefault(); // Assert Assert.AreEqual(nameof(TrucksController.Index), result?.ActionName, "It should edit and redirect to Index"); Assert.AreEqual(chassis, truck.Chassis, "Item was not updated"); }
public TruckWindow2() { InitializeComponent(); TruckViewModel = new TruckViewModel(); TruckGrid.DataContext = TruckViewModel; }
public void Update_ShouldUpdateItem( int id, string chassis, EnumModelViewModel model, int year, int modelYear) { // Arrange var truckViewModel = new TruckViewModel { Id = id, Chassis = chassis, Model = model, Year = year, ModelYear = modelYear }; // Act TruckService.Update(truckViewModel); var truck = FakeUnitOfWork.TruckRepository.GetAll(t => t.Chassis.Equals(chassis)).FirstOrDefault(); // Assert Assert.AreEqual(chassis, truck.Chassis, "Item was not updated"); }
public IHttpActionResult Post(TruckViewModel truck) { _truckService.CreateTruck(truck); _maintenancePlanDetailService.UpdatePlan(truck.MaintenanceItems, "0", truck.TruckC); _inspectionPlanDetailService.Add(truck.Inspection, "0", truck.TruckC); return(Ok()); }
public TruckSaveUpdateViewModel SearchTruck(TruckSaveUpdateViewModel truck) { var truckSearchResult = new Truck(); var truckViewModel = new TruckViewModel(); if (!string.IsNullOrEmpty(truck.TruckNumber)) { if (!_validate.Numeric(truck.TruckNumber)) { truck.TruckNumberIsValid = false; } else { int truckNumberConvertedToInt = 0; Int32.TryParse(truck.TruckNumber, out truckNumberConvertedToInt); truckSearchResult = _truckContext.Collection().Where(t => t.TruckNumber == truckNumberConvertedToInt).FirstOrDefault(); if (truckSearchResult == null) { truck.ExistInDB = false; } else { truck.Id = truckSearchResult.Id; truck.TruckNumber = truckSearchResult.TruckNumber.ToString(); truck.VIN = truckSearchResult.VIN; truck.Manufacturer = truckSearchResult.TruckManufacturer.ManufacturerDescription; truck.Model = truckSearchResult.TruckModel.ModelDescription; truck.Year = truckSearchResult.TruckYear.ModelYear.ToString(); truck.Status = truckSearchResult.Status; truck.StatusLabel = truckSearchResult.MessageBasedOnStatusSelection; } } } return(truck); }
public IActionResult Create(TruckViewModel collection) { if (collection.DeliveryYear != DateTime.Now.Year) { ModelState.AddModelError("DeliveryYear", "Delivery year must be current year"); return(View(collection)); } if (collection.ModelYear < collection.DeliveryYear || collection.ModelYear > collection.DeliveryYear + 1) { ModelState.AddModelError("ModelYear", "Model year must be current year or next year"); return(View(collection)); } Truck truck = new Truck(); truck.ModelId = collection.ModelId; truck.ModelName = Enum.GetName(typeof(Model), truck.ModelId); truck.ModelYear = collection.ModelYear; truck.DeliveryYear = collection.DeliveryYear; db.Trucks.Add(truck); db.SaveChanges(); return(RedirectToAction("Index")); }
public JsonResult SaveMultiTruck(TruckViewModel tv) { if (ModelState.IsValid) { var truck = Mapper.Map <Truck>(tv); var result = dispatchManager.SaveTruck(truck); if (result.Ok) { return(new JsonResult() { Data = true }); } else { var strErr = string.Join(";", result.Errors); return(new JsonResult() { Data = strErr }); } } return(new JsonResult() { Data = false }); }
public IActionResult Edit(TruckViewModel truck) { if (!ModelState.IsValid) { TruckEditViewModel tevm = new TruckEditViewModel { Chassis = truck.Chassis, BuildingYear = truck.BuildingYear, ModelYear = truck.ModelYear, TruckModelList = PopulateList(), TruckModel = new SelectListItem { Value = truck.TruckModel.Value } }; return(View(tevm)); } Truck t = new Truck { Chassis = truck.Chassis, BuildingYear = truck.BuildingYear, ModelYear = truck.ModelYear, TruckModelId = Convert.ToInt32(truck.TruckModel.Value) }; truckRepository.Update(t); return(RedirectToAction("Index")); }
public void Update(TruckViewModel truckViewModel) { var truck = Mapper.Map <Truck>(truckViewModel); UnitOfWork.TruckRepository.Update(truck); UnitOfWork.Commit(); }
public TruckView() { InitializeComponent(); DataContext = this; viewModel = new TruckViewModel(); TrucksColections = new ObservableCollection <Truck>(); SearchComboBox.ItemsSource = Enum.GetValues(typeof(TruckColumns)); }
public void CreateTruck(TruckViewModel truckViewModel) { var truck = Mapper.Map <TruckViewModel, Truck_M>(truckViewModel); _truckRepository.Add(truck); SaveTruck(); }
public IActionResult Delete([Bind] TruckViewModel truck) { if (truck != null && truck.TruckId != null && truck.TruckId != 0) { _service.DeleteTruck((int)truck.TruckId); } return(RedirectToAction("ListTrucks")); }
// GET: Truck/Create public ActionResult Create() { var truckViewModel = new TruckViewModel { Year = DateTime.Today.Year }; return(View(truckViewModel)); }
public void UpdateTruck(TruckViewModel truck) { var truckToRemove = _truckRepository.GetById(truck.TruckC); var updateTruck = Mapper.Map <TruckViewModel, Truck_M>(truck); _truckRepository.Delete(truckToRemove); _truckRepository.Add(updateTruck); SaveTruck(); }
public IActionResult Delete(int id, TruckViewModel collection) { Truck truck = db.Trucks.Find(id); db.Trucks.Remove(truck); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Find_ShouldFindItem( int id, string chassis) { // Act TruckViewModel truckViewModel = TruckService.Find(id); // Assert Assert.AreEqual(chassis, truckViewModel.Chassis, "It should return the same Chassis"); }
public IActionResult Delete(int id) { var truck = _service.FindTruckById(id); if (truck != null) { var truckmodel = new TruckViewModel(truck); return(View(truckmodel)); } return(RedirectToAction("Error")); }
public IActionResult Delete(TruckViewModel truck) { Truck t = truckRepository.GetSingle(truck.Chassis); if (t == null) { return(View("Delete", truck.Chassis)); } truckRepository.Delete(t); return(RedirectToAction("Index")); }
public ActionResult Add(TruckViewModel truck) { if (ModelState.IsValid) { truck.TypeCar = new Service <TypeCarViewModel, TypeCar>(_unitOfWork).Get(STOConst.TypeCar.Truck); var service = new Service <TruckViewModel, Truck>(_unitOfWork); service.Save(truck); } else { } return(RedirectToAction("ShowResult", "Home")); }
public ActionResult Delete(int id, TruckViewModel truckViewModel) { try { TruckService.Remove(id); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { Logger.LogError(ex, ex.Message); return(View(truckViewModel)); } }
public IActionResult Delete(int id) { Truck truck = db.Trucks.Find(id); TruckViewModel truckVm = new TruckViewModel(); truckVm.Id = truck.Id; truckVm.ModelId = truck.ModelId; truckVm.ModelName = truck.ModelName; truckVm.DeliveryYear = truck.DeliveryYear; truckVm.ModelYear = truck.ModelYear; return(View(truckVm)); }
public void DeleteTruck_Fail() { var controller = new TruckController(repo); var truck = new TruckViewModel { Chassis = "ASDFASDFASDFASDFA", BuildingYear = 2020, ModelYear = 2021 }; var data = controller.Delete(truck); ViewResult result = data as ViewResult; Assert.AreEqual("Delete", result.ViewName); }
public void Test_Save_Truck_Return_View() { dispatchManager.Setup(foo => foo.SaveTruck(It.IsAny <Truck>())).Returns(new OpResult() { Ok = true }); var tv = new TruckViewModel() { TruckName = "New Name", ActiveSafetySystemNote = "Active Safety System Note" }; var result = ctrl.SaveTruck(tv); Assert.IsInstanceOf(typeof(ActionResult), result); }
public IActionResult Edit([Bind] TruckViewModel updated) { var truck = _service.FindTruckById((int)updated.TruckId); if (truck.TruckModelId != updated.ModelId) { truck.TruckModelId = (int)updated.ModelId; var model = _service.FindModelById((int)updated.ModelId); truck.Model = model; } truck.Description = updated.Description; truck.ManufacturingYear = updated.ManufacturingYear; truck.ModelYear = updated.ModelYear; _service.SaveOrUpdateTruck(truck); return(RedirectToAction("ListTrucks")); }
public void Edit_ShouldReturnValidationError( string key, string message) { // Arrange var truckViewModel = new TruckViewModel(); Controller.ModelState.AddModelError(key, message); // Act var result = Controller.Edit(0, truckViewModel) as ViewResult; var error = result.ViewData.ModelState.GetValueOrDefault(key).Errors.FirstOrDefault(v => v.ErrorMessage == message); // Assert Assert.AreEqual(message, error.ErrorMessage, "It should be valid"); }
public void Delete_ShouldDeleteItem(int id) { // Arrange var truckViewModel = new TruckViewModel { Id = id }; // Act var result = Controller.Delete(id, truckViewModel) as RedirectToActionResult; var truck = FakeUnitOfWork.TruckRepository.GetAll(t => t.Id == id).FirstOrDefault(); // Assert Assert.AreEqual(nameof(TrucksController.Index), result?.ActionName, "It should delete and redirect to Index"); Assert.IsNull(truck, "Item was not deleted"); }
public IActionResult Create(TruckViewModel truck) { if (!ModelState.IsValid) { TruckEditViewModel tevm = new TruckEditViewModel { Chassis = truck.Chassis, BuildingYear = truck.BuildingYear, ModelYear = truck.ModelYear, TruckModelList = PopulateList(), TruckModel = new SelectListItem { Value = truck.TruckModel.Value } }; return(View(tevm)); } if (truck.TruckModel.Value == "-1") { TruckEditViewModel tevm = new TruckEditViewModel { Chassis = truck.Chassis, BuildingYear = truck.BuildingYear, ModelYear = truck.ModelYear, TruckModelList = PopulateList(), TruckModel = new SelectListItem { Value = truck.TruckModel.Value } }; ModelState.AddModelError("TruckModel.Value", "Você deve selecionar um modelo"); return(View("Create", tevm)); } Truck t = new Truck { Chassis = RandomString(17), BuildingYear = truck.BuildingYear, ModelYear = truck.ModelYear, TruckModelId = Convert.ToInt32(truck.TruckModel.Value) }; truckRepository.Add(t); return(RedirectToAction("Index")); }
public IActionResult Details(string chassis) { Truck t = truckRepository.GetSingle(chassis); TruckViewModel tvm = new TruckViewModel { Chassis = t.Chassis, BuildingYear = t.BuildingYear, ModelYear = t.ModelYear, TruckModel = new SelectListItem { Text = t.TruckModel.ModelCode, Value = t.TruckModel.Id.ToString() } }; return(View(tvm)); }
public IActionResult Create([Bind] TruckViewModel truck) { if (ModelState.IsValid) { var truckModel = _service.FindModelById((int)truck.ModelId); var newTruck = new Truck() { ModelYear = truck.ModelYear, Description = truck.Description, ManufacturingYear = truck.ManufacturingYear, Model = truckModel }; _service.SaveOrUpdateTruck(newTruck); } return(RedirectToAction("ListTrucks")); }
public ActionResult SaveTruck(TruckViewModel tv) { if (ModelState.IsValid) { var truck = Mapper.Map <Truck>(tv); var result = dispatchManager.SaveTruck(truck); if (result.Ok) { return(View("index")); } else { var strErr = string.Join(";", result.Errors); ModelState.AddModelError("Error:", strErr); } } return(View(tv)); }