예제 #1
0
        public JsonResult RemoveRealtyImage(string realtyId, string image)
        {
            int id = Convert.ToInt32(realtyId);

            try
            {
                var realty = _realtyRepository.Read(id);

                if (realty == null)
                {
                    throw new Exception();
                }

                if (realty.UserId != WebSecurity.CurrentUserId && !User.IsInRole("Administrator"))
                {
                    throw new Exception();
                }

                _realtyPhotoRepository.DeleteImage(id, image);
                var path = AppDomain.CurrentDomain.BaseDirectory + image;
                System.IO.File.Delete(path);
                path = AppDomain.CurrentDomain.BaseDirectory + ProjectConfiguration.Get.FilePaths["realty_thumb"] + "//" + image.Split('/').Last();
                System.IO.File.Delete(path);
            }
            catch
            {
                return(Json(new { status = "fail" }, "text/html"));
            }

            return(Json(new { status = "success" }, "text/html"));
        }
예제 #2
0
        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);
        }