public static CarPictureModel ToObject(DataRow reader) { CarPictureModel carPictureModel = new CarPictureModel(); carPictureModel.carPictureLink = reader[0].ToString(); if (!carPictureModel.carPictureLink.Equals(string.Empty) && !carPictureModel.carPictureLink.Equals("")) { carPictureModel.carPictureLink = "/assets/images/cars/" + carPictureModel.carPictureLink; } carPictureModel.carPictureName = reader[0].ToString(); carPictureModel.numberOfCars = int.Parse(reader[1].ToString()); Debug.WriteLine("carPictureModel: " + carPictureModel.ToString()); return(carPictureModel); }
public List <CarPictureModel> GetAllCarImagesAndNumberOfCars() { DataTable dt = new DataTable(); List <CarPictureModel> arrCarPictures = new List <CarPictureModel>(); using (MySqlCommand command = new MySqlCommand()) { dt = GetMultipleQuery(CarStringsMySql.GetAllCarImagesAndNumberOfCars()); } foreach (DataRow ms in dt.Rows) { CarPictureModel carPictureModel = CarPictureModel.ToObject(ms); arrCarPictures.Add(carPictureModel); } return(arrCarPictures); }
public CarPictureModel GetNumberOfCarWithImage(string pictureName) { if (pictureName.Equals("")) { throw new ArgumentOutOfRangeException(); } DataTable dt = new DataTable(); CarPictureModel carPictureModelSql = new CarPictureModel(); using (MySqlCommand command = new MySqlCommand()) { dt = GetMultipleQuery(CarStringsMySql.GetNumberOfCarWithImage(pictureName)); } foreach (DataRow ms in dt.Rows) { carPictureModelSql = CarPictureModel.ToObject(ms); } return(carPictureModelSql); }
public IActionResult DeleteCar(string number) { try { string carImage = carsRepository.DeleteCar(number); carImage = carImage.Trim(); CarPictureModel carsPictureModel = carsRepository.GetNumberOfCarWithImage(carImage); if (carsPictureModel.numberOfCars == 0) { string filePath = environment.WebRootPath + "/images/cars/" + carImage; var file = new FileInfo(filePath); if (file.Exists) { file.Delete(); } } return(NoContent()); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }