public async Task <IActionResult> Edit(int VehicleId, [Bind("VehicleId,UserId,Make,Model,Year,Colour,Plate")] Vehicle vehicle) { ViewBag.UserId = HttpContext.Session.GetInt32("UserId"); vehicle.UserId = ViewBag.UserId; if (VehicleId != vehicle.VehicleId) { return(NotFound()); } if (ModelState.IsValid) { try { _vehicleLogic.UpdateVehicle(vehicle); await _vehicleLogic.Save(); } catch (DbUpdateConcurrencyException) { if (!VehicleExists(vehicle.VehicleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(ListVehicles))); } return(View(vehicle)); }
public IActionResult UpdateVehicle([FromBody] VehicleModel model) { try { if (model == null) { return(BadRequest("Body content is not valid!")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = model.Map <VehicleEntity>(); entity.ManufactureDate = entity.ManufactureDate.ToLocalTime(); entity = _vehicleLogic.UpdateVehicle(entity); if (entity == null) { return(BadRequest("Somthing went wrong while updating model in DB!")); } return(Ok(entity)); } catch (Exception e) { return(StatusCode(500, e)); } }