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[2].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 HttpResponseMessage DeleteCar(string deleteByNumber) { try { string carImage = carsRepository.DeleteCar(deleteByNumber); carImage = carImage.Trim(); CarPictureModel carsPictureModel = carsRepository.GetNumberOfCarWithImage(carImage); if (carsPictureModel.numberOfCars == 0) { string filePath = HttpContext.Current.Server.MapPath("~/assets/images/cars/" + carImage); if (File.Exists(filePath)) { File.Delete(filePath); } } if (!carImage.Equals("") && !carImage.Equals(String.Empty) && carImage != null) { HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.NoContent) { }; return(hrm); } HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError) { }; return(hr); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(errors.ToString()) }; return(hr); } }
public HttpResponseMessage DeleteCar(string number) { try { string carImage = carsRepository.DeleteCar(number); carImage = carImage.Trim(); CarPictureModel carsPictureModel = carsRepository.GetNumberOfCarWithImage(carImage); if (carsPictureModel.numberOfCars == 0) { string filePath = HttpContext.Current.Server.MapPath("~/assets/images/cars/" + carImage); if (File.Exists(filePath)) { File.Delete(filePath); } } return(Request.CreateResponse(HttpStatusCode.NoContent)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors)); } }