コード例 #1
0
        public ActionResult GetArticleTableInline(int pk, string value, string name)
        {
            var art = new ArticleManager();

            art.EditItemField(pk, name, value);
            return(Json(new
            {
                result = true
            }));
        }
コード例 #2
0
        public ActionResult ArticleImageDelete(int id)
        {
            var art     = new ArticleManager();
            var mesage1 = HttpContext.User.Identity.IsAuthenticated;
            var mesage2 = HttpContext.Request.IsAuthenticated;
            var res     = false;

            try
            {
                string serverUrl = HttpContext.Server.MapPath("~/uploads/Images/Articles/" + id.ToString() + "/");
                Files.DeleteDirectory(serverUrl);
                art.EditItemField(id, "imgPath", null);
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
            }
            return(Json(new
            {
                result = res,
                msg = ""
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        //[Authorize(Roles = "admin")] - Данный атрибут отключён из-за некорректной работы uploadify в opere
        public ActionResult ArticleImageSave()
        {
            var context      = HttpContext;
            var mesage1      = HttpContext.User.Identity.IsAuthenticated;
            var mesage2      = HttpContext.Request.IsAuthenticated;
            var mesage3      = Request.IsAjaxRequest();
            var art          = new ArticleManager();
            var acim         = new ArticleCatalogImagesManager();
            var res          = false;
            int suggestionID = 0;

            try
            {
                string toSaveDirectory = context.Request.Params["toSaveDirectory"];
                suggestionID = RDL.Convert.StrToInt(context.Request.Params["suggestionID"], 0);
                var    isPropImages  = RDL.Convert.StrToInt(context.Request.Params["isPropImages"], 0);
                string propertyName  = context.Request.Params["propertyName"];
                string propertyValue = context.Request.Params["propertyValue"] == null ? "" : context.Request.Params["propertyValue"];

                HttpPostedFileBase file = context.Request.Files["Filedata"];
                if (file != null && !string.IsNullOrEmpty(toSaveDirectory) && suggestionID > 0)
                {
                    string serverUrl = context.Server.MapPath("~" + toSaveDirectory + "/" + suggestionID + "/");//сохраняем рисунки с измен размерами

                    if (isPropImages > 0)
                    {
                        if (propertyValue == "")
                        {
                            serverUrl = context.Server.MapPath("~" + toSaveDirectory + "/" + suggestionID + "/property/" + propertyName + "/");
                        }
                        else
                        {
                            serverUrl = context.Server.MapPath("~" + toSaveDirectory + "/" + suggestionID + "/property/" + propertyName + "/" + propertyValue + "/");
                        }
                    }

                    if (Directory.Exists(serverUrl))
                    {
                        Files.DeleteDirectoryFiles(serverUrl);
                    }
                    else
                    {
                        Directory.CreateDirectory(serverUrl);
                    }

                    var fileGuid     = Guid.NewGuid();      //
                    var fileGuidName = fileGuid.ToString() + Path.GetExtension(file.FileName);

                    //------------преобразование размера---------------------------------------------------------
                    Image bmp         = Bitmap.FromStream(file.InputStream);
                    Image bmp_resized = Img.ResizeImage(bmp, new SizeF(1024, 1024));     //преобразовали к размеру 1024*...
                    bmp_resized.Save(serverUrl + fileGuidName);                          //сохранили в папке

                    Image  bmp_resized_mini = Img.ResizeImage(bmp, new SizeF(300, 300)); //получаем миниатюру 300*...
                    string fileNameMini     = Path.GetFileNameWithoutExtension(fileGuidName) + "_mini";
                    fileNameMini = fileNameMini + Path.GetExtension(fileGuidName);
                    bmp_resized_mini.Save(serverUrl + fileNameMini);

                    // Сохраняем в базу путь к картинке
                    art.EditItemField(suggestionID, "imgPath", toSaveDirectory + "/" + suggestionID + "/" + fileNameMini);
                    res = true;
                }
            }
            catch (Exception ex)
            {
                res = false;
            }
            return(Json(new
            {
                result = res,
                msg = ""
            }, JsonRequestBehavior.AllowGet));
        }