public IActionResult GetVehicleById(int VehicleId) { //string GetConnectionString = VehiclesController.GetConnectionString(); List <VehiclesDetails> vechileList = new List <VehiclesDetails>(); try { DataTable dt = Data.Vehicles.GetVehicleById(VehicleId); VehiclesDetails vechile = new VehiclesDetails(); if (dt.Rows.Count > 0) { //for (int i = 0; i < dt.Rows.Count; i++) //{ vechile.VehicleId = (dt.Rows[0]["VehicleId"] == DBNull.Value ? 0 : (int)dt.Rows[0]["VehicleId"]); vechile.UserId = (dt.Rows[0]["UserId"] == DBNull.Value ? 0 : (int)dt.Rows[0]["UserId"]); vechile.MakeId = (dt.Rows[0]["MakeId"] == DBNull.Value ? 0 : (int)dt.Rows[0]["MakeId"]); vechile.Make = (dt.Rows[0]["Make"] == DBNull.Value ? "" : dt.Rows[0]["Make"].ToString()); vechile.Model = (dt.Rows[0]["Model"] == DBNull.Value ? "" : dt.Rows[0]["Model"].ToString()); vechile.Year = (dt.Rows[0]["Year"] == DBNull.Value ? 0000 : (int)dt.Rows[0]["Year"]); vechile.Color = (dt.Rows[0]["Color"] == DBNull.Value ? "" : dt.Rows[0]["Color"].ToString()); vechile.LicencePlate = (dt.Rows[0]["LicensePlate"] == DBNull.Value ? "" : dt.Rows[0]["LicensePlate"].ToString()); vechile.SpecialNotes = (dt.Rows[0]["SpecialNotes"] == DBNull.Value ? "" : dt.Rows[0]["SpecialNotes"].ToString()); vechile.IsDeleted = (dt.Rows[0]["IsDeleted"] == DBNull.Value ? false : (bool)dt.Rows[0]["IsDeleted"]); vechile.CreatedDate = (dt.Rows[0]["CreatedDate"] == DBNull.Value ? "" : dt.Rows[0]["CreatedDate"].ToString()); vechile.ModifiedDate = (dt.Rows[0]["ModifiedDate"] == DBNull.Value ? "" : dt.Rows[0]["ModifiedDate"].ToString()); vechile.VehicleImageURL = (dt.Rows[0]["VehicleImageURL"] == DBNull.Value ? "" : dt.Rows[0]["VehicleImageURL"].ToString()); //vechile.ImageType = (dt.Rows[0]["ImageType"] == DBNull.Value ? "" : dt.Rows[0]["ImageType"].ToString()); vechileList.Add(vechile); //} return(StatusCode((int)HttpStatusCode.OK, vechile)); } else { string[] data = new string[0]; return(StatusCode((int)HttpStatusCode.OK, data)); // return StatusCode((int)HttpStatusCode.OK, new { }); } } catch (Exception e) { string SaveErrorLog = Data.Common.SaveErrorLog("Vehicle", e.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message } })); } }
public IActionResult GetUserVehicleDetails(int UserId) { //string GetConnectionString = VehiclesController.GetConnectionString(); List <VehiclesDetails> vechileList = new List <VehiclesDetails>(); try { DataTable dt = Data.Vehicles.GetUserVehicleDetails(UserId == null ? 0 : UserId); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { if ((dt.Rows[i]["VehicleId"]) != null) { VehiclesDetails vechile = new VehiclesDetails(); vechile.Email = (dt.Rows[i]["Email"] == DBNull.Value ? "" : dt.Rows[i]["Email"].ToString()); vechile.Name = (dt.Rows[i]["Name"] == DBNull.Value ? "" : dt.Rows[i]["Name"].ToString()); vechile.PhoneNumber = (dt.Rows[i]["PhoneNumber"] == DBNull.Value ? "" : dt.Rows[i]["PhoneNumber"].ToString()); vechile.Address = (dt.Rows[i]["LocationFullAddress"] == DBNull.Value ? "" : dt.Rows[i]["LocationFullAddress"].ToString()); vechile.UserId = (dt.Rows[i]["UserId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["UserId"]); vechile.MakeId = (dt.Rows[i]["MakeId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["MakeId"]); vechile.VehicleId = (dt.Rows[i]["VehicleId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["VehicleId"]); vechile.Make = (dt.Rows[i]["Make"] == DBNull.Value ? "" : dt.Rows[i]["Make"].ToString()); vechile.Model = (dt.Rows[i]["Model"] == DBNull.Value ? "" : dt.Rows[i]["Model"].ToString()); vechile.Year = (dt.Rows[i]["Year"] == DBNull.Value ? 0000 : (int)dt.Rows[i]["Year"]); vechile.Color = (dt.Rows[i]["Color"] == DBNull.Value ? "" : dt.Rows[i]["Color"].ToString()); vechile.LicencePlate = (dt.Rows[i]["LicensePlate"] == DBNull.Value ? "" : dt.Rows[i]["LicensePlate"].ToString()); vechile.SpecialNotes = (dt.Rows[i]["SpecialNotes"] == DBNull.Value ? "" : dt.Rows[i]["SpecialNotes"].ToString()); vechile.IsDeleted = (dt.Rows[i]["IsDeleted"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsDeleted"]); vechile.VehicleImageURL = (dt.Rows[i]["VehicleImageURL"] == DBNull.Value ? "" : dt.Rows[i]["VehicleImageURL"].ToString()); vechile.NextService = (dt.Rows[i]["NextService"] == DBNull.Value ? "" : dt.Rows[i]["NextService"].ToString()); vechile.DueService = (dt.Rows[i]["DueService"] == DBNull.Value ? "" : dt.Rows[i]["DueService"].ToString()); vechile.IsServiceScheduled = (dt.Rows[i]["IsServiceScheduled"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsServiceScheduled"]); //vechile.ImageType = (dt.Rows[i]["ImageType"] == DBNull.Value ? "" : dt.Rows[i]["ImageType"].ToString()); //vechile.UserCreatedDate = (dt.Rows[i]["UserCreatedDate"] == DBNull.Value ? "" : dt.Rows[i]["UserCreatedDate"].ToString()); //vechile.VehicleCreatedDate = (dt.Rows[i]["VehicleCreatedDate"] == DBNull.Value ? "" : dt.Rows[i]["VehicleCreatedDate"].ToString()); //vechile.IsPromoCodeApplicable = (dt.Rows[i]["IsPromoCodeApplicable"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsPromoCodeApplicable"]); // vechile.IsPhoneNumVerified = (dt.Rows[i]["IsPhoneNumVerified"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsPhoneNumVerified"]); // vechile.IsPromoCodeApplicable = (dt.Rows[i]["IsPromoCodeApplicable"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsPromoCodeApplicable"]); // vechile.SourceofReg = (dt.Rows[i]["SourceofReg"] == DBNull.Value ? "" : dt.Rows[i]["SourceofReg"].ToString()); vechileList.Add(vechile); } } return(StatusCode((int)HttpStatusCode.OK, vechileList)); } else { string[] data = new string[0]; return(StatusCode((int)HttpStatusCode.OK, data)); // return StatusCode((int)HttpStatusCode.OK, new { }); } } catch (Exception e) { string SaveErrorLog = Data.Common.SaveErrorLog("Vehicles", e.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message } })); } }