public async Task <IActionResult> CreateVehicle(VehicleModel vehModel) { if (vehModel == null || vehModel.licenceNum == null) { return(RedirectToAction("Index")); } //Get makes IEnumerable <MakeModel> makeList = MakeModel.CreateModelNumerable(await _beService.GetMakesAsync()); VehicleDTO searchdto = await _beService.GetVehicleAsync(vehModel.licenceNum); if (searchdto != null) { //Add to dropdown ViewBag.selList = makeList; return(View("VehicleCreate", vehModel)); } vehModel.state = "In"; VehicleDTO dto = VehicleDTO.CreateDTO(vehModel); string response = await _beService.InsertVehicleAsync(dto); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditVehicle(VehicleModel vehModel) { if (vehModel == null || vehModel.licenceNum == null) { return(RedirectToAction("Index")); } VehicleDTO dto = VehicleDTO.CreateDTO(vehModel); string response = await _beService.UpdateVehicleAsync(dto); if (response != "Success") { return(RedirectToAction("Index")); } return(View("Details", vehModel.licenceNum)); }
public async Task <ActionResult> ConfirmClockVehicle(ClockModel cModel) { //Due to the lack of an auth/identitfy of the driver //This would is acting as a placeholder for the current driver ID Guid driverID = Guid.NewGuid(); string updateResponse = null; //If clock in, check for damages against the AI service if (cModel.clock == "In") { //Generate a new ID for the potential damage model Guid damageID = Guid.NewGuid(); //Create ImageDTO list for each image to be added as we go through the loop of uploads. List <ImageDTO> vehicleImages = new List <ImageDTO>(); //Set state of tracking = null //Used to track the verdict. //This allows to continue processing all uploaded images but still know that one showed damage string verdictTracker = "Undamaged"; //Set counter to 0. This is used to add a suffix count to the end of the image filename when uploaded int count = 0; //Loop through uploads foreach (IFormFile img in cModel.imgs) { //Increment the count count++; //Create a new image DTO. ImageDTO newImageDTO = ImageDTO.CreateDTO(ImageDTO.GenerateImageId(damageID, cModel.time, count.ToString(), img), img); vehicleImages.Add(newImageDTO); try { //Check the damage of the images against the AI model APIDTO returnApiDto = await _damageService.DamageCheckImg(newImageDTO); //Extract at the decimal percentage of guesses for each tag double damagedGuess = returnApiDto.predictions.FirstOrDefault(x => x.tagName == "Damaged").probability; double wholeGuess = returnApiDto.predictions.FirstOrDefault(x => x.tagName == "Whole").probability; //If both results are over 0.1 then cant say for certain. i.e level of uncertainty //This is to make sure a Staff member will manually resolve it if (wholeGuess >= 0.1 && damagedGuess >= 0.1) { //If not already set to damage from previous image. //Test this because Damaged is a stronger case than Inclonclusive if (verdictTracker == "Undamaged") { verdictTracker = "Inconclusive"; } } //If the verdict is Damaged else if (damagedGuess > wholeGuess) { //If Damaged then overrules the above conclusion of a previous image verdictTracker = "Damaged"; } } catch { //In any case of an error, set to Inclousive verdictTracker = "Inconclusive"; } } //After loop of images, check the state. //If either damage or incloncsive if (verdictTracker != "Undamaged") { try { //Set the new state to if (verdictTracker == "Inconclusive") { cModel.clock = "Inconclusive"; } //Damaged else { cModel.clock = "Damaged"; } //Create and Insert a Damage history record to keep track of vehicle damages DamageHistoryDTO newDamageDTO = DamageHistoryDTO.CreateDTO(DamageHistoryModel.CreateModel(cModel, damageID, driverID)); updateResponse = await _vehicleService.InsertDamageHistoryAsync(newDamageDTO); if (updateResponse != "Success") { return(RedirectToAction("ClockVehicle")); } //Update Vehicle with new state cModel.vehicle.state = "Under Investigation"; VehicleDTO newVehDto = VehicleDTO.CreateDTO(cModel.vehicle); updateResponse = await _vehicleService.UpdateVehicleAsync(newVehDto); if (updateResponse != "Success") { return(RedirectToAction("ClockVehicle")); } //Loop and upload images to blob storage foreach (ImageDTO img in vehicleImages) { //Save Images to the blob storage. updateResponse = await _blobService.UploadImage(img); if (updateResponse != "Success") { return(RedirectToAction("ClockVehicle")); } } //Return back to confirmed view return(View("ClockConfirmed", cModel)); } catch { //if error at anypoint, restart the form by rdirecting to initial action return(RedirectToAction("ClockVehicle")); } } } //Update state of the vehicle in vehicle table cModel.vehicle.state = cModel.clock; VehicleDTO vehDTO = VehicleDTO.CreateDTO(cModel.vehicle); updateResponse = await _vehicleService.UpdateVehicleAsync(vehDTO); if (updateResponse != "Success") { return(RedirectToAction("ClockVehicle")); } //Insert into the history table. //Note: The DriverID would be replaced with identification if implemented as mentioned above Guid historyID = Guid.NewGuid(); ClockHistoryDTO newDTO = ClockHistoryDTO.CreateDTO(cModel, historyID, driverID); updateResponse = await _vehicleService.InsertClockHistoryAsync(newDTO); if (updateResponse != "Success") { return(RedirectToAction("ClockVehicle")); } //Return back to confirmed view return(View("ClockConfirmed", cModel)); }