public ResultModel UpdateCarPhoto(CarPhotoModel model) { Car car = db.Car.Where(s => s.carId == model.carId).SingleOrDefault(); if (car == null) { result.success = false; result.message = "Araç bulunamadı."; return(result); } if (car.carPhoto != "placeholder.png") { string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/" + car.carPhoto); if (File.Exists(path)) { File.Delete(path); } } string data = model.photoData; string base64 = data.Substring(data.IndexOf(',') + 1); base64 = base64.Trim('\0'); byte[] imagebytes = Convert.FromBase64String(base64); string fileName = car.carId + model.photoExtension.Replace("image/", "."); using (var ms = new MemoryStream(imagebytes, 0, imagebytes.Length)) { Image image = Image.FromStream(ms, true); image.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/Files/" + fileName)); } car.carPhoto = fileName; db.SaveChanges(); result.success = true; result.message = "Fotoğraf güncellendi."; return(result); }
public CarPhotoViewModel(CarPhotoModel model) { Id = model.Id; Contents = model.Contents; Image = model.Image; }