public ActionResult Upload(Guid id) { var model = new ImageUploadModel() { PropertyId = id }; return View("_ImageUpload", model); }
public ActionResult Upload(ImageUploadModel model) { if (ModelState.IsValid) { foreach(var image in model.Images) { var fileName = Path.GetFileName(image.FileName); var folder = Path.Combine(@"C:\CDN\", model.PropertyId.ToString()); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if (Path.GetExtension(image.FileName) == ".jpg") { if (image != null && image.ContentLength > 0) { var propertyImageId = _landlordService.AddPropertyImage(model.PropertyId); var path = Path.Combine(folder, propertyImageId.ToString()); path = string.Format("{0}.jpg", path); image.SaveAs(path); } } } return RedirectToAction("View", "Property", new { id = model.PropertyId }); } else { return View("_ImageUpload", model); } }