public async Task <ActionResult> UpdateVehicleMaintenanceInfo([FromBody] VehicleMaintenanceInfo data, string username, string vehicleId) { try { if (data != null && username != null && vehicleId != null) { var delete = await MH.DeleteSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null); if (delete != null) { var insert = MH.InsertNewVehicleMaintenanceInfo(data, vehiclemaintenanceinfoCollection); if (insert != null) { var getVehicle = MH.GetSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null).Result; AL.CreateLog(username, "UpdateVehicleMaintenanceInfo", BsonSerializer.Deserialize <VehicleMaintenanceInfo>(getVehicle), data, activitylog_collection); return(Ok(new ResponseData { Code = "200", Message = "Updated" })); } else { return(BadRequest(new ResponseData { Code = "401", Message = "Update failed" })); } } else { return(BadRequest(new ResponseData { Code = "404", Message = "Vehicle maintenance info not found" })); } } else { return(BadRequest(new ResponseData { Code = "402", Message = "Bad request" })); } } catch (Exception ex) { SL.CreateLog("VehicleController", "UpdateVehicleMaintenanceInfo", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
public async Task <ActionResult> UpdateTripInfo([FromBody] TripInfo data, string username, string tripId) { try { if (data != null && username != null && tripId != null) { var getTrip = MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result; if (getTrip != null) { var delete = await MH.DeleteSingleObject(tripinfo_collection, "TripId", tripId, null, null); var tripData = BsonSerializer.Deserialize <TripInfo>(getTrip); data.Id = tripData.Id; data.TripId = tripData.TripId; await trip_db.GetCollection <TripInfo>("TripInfo").InsertOneAsync(data); AL.CreateLog(username, "UpdateTripInfo", BsonSerializer.Deserialize <TripInfo>(getTrip), data, activitylog_collection); return(Ok(new ResponseData { Code = "200", Message = "Updated" })); } else { return(BadRequest(new ResponseData { Code = "404", Message = "Trip info not found" })); } } else { return(BadRequest(new ResponseData { Code = "401", Message = "Bad Request" })); } } catch (Exception ex) { SL.CreateLog("TripController", "UpdateTripInfo", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }