public JsonResult RemoveAnnouncementImage(string announcementId, string image) { int id = Convert.ToInt32(announcementId); try { var announcement = _announcementRepository.Read(id); if (announcement == null) { throw new Exception(); } if (announcement.UserId != WebSecurity.CurrentUserId && !User.IsInRole("Administrator")) { throw new Exception(); } _announcementImageRepository.DeleteImage(id, image); var path = AppDomain.CurrentDomain.BaseDirectory + image; System.IO.File.Delete(path); } catch { return(Json(new { status = "fail" }, "text/html")); } return(Json(new { status = "success" }, "text/html")); }
public bool RemoveImage(string announcementId, string imageName, ImagesType type) { var id = Convert.ToInt32(announcementId); try { switch (type) { case ImagesType.Anouncement: var announcement = _announcement.Read(id); if (announcement == null) { throw new Exception(); } _announcementImage.DeleteImage(id, imageName); break; case ImagesType.Realty: var realty = _realty.Read(id); if (realty == null) { throw new Exception(); } _realtyImage.DeleteImage(id, imageName); break; } RemoveImage(imageName, type); } catch { return(false); } return(true); }