示例#1
0
 public void SaveImage(ImageUnload image)
 {
     Racoonogram.Models.Image imEdit = GetImage(image.Id);
     imEdit.Category = image.Category.ToLower();
     imEdit.KeyWords = image.KeyWords.ToLower();
     if (!String.IsNullOrEmpty(image.Description))
     {
         imEdit.Description = image.Description.Substring(0, 1).ToUpper() + image.Description.Substring(1);
     }
     if (!String.IsNullOrEmpty(image.Colors))
     {
         imEdit.Colors = image.Colors.ToLower();
     }
     imEdit.Price = image.Price;
     db.SaveChanges();
 }
示例#2
0
        // [ValidateAntiForgeryToken]
        public JsonResult Upload()
        {
            Racoonogram.Models.Image i = new Racoonogram.Models.Image();
            if (Request.Form["Category"] == null || Request.Form["Category"] == "")
            {
                return(Json("! Поле 'Категория' является обязательным для заполнения"));
            }
            i.Category = Request.Form["Category"].ToLower();
            if (Request.Form["KeyWords"] == null || Request.Form["KeyWords"] == "")
            {
                return(Json("! Поле 'Ключевые слова' является обязательным для заполнения"));
            }
            i.KeyWords = Request.Form["KeyWords"].ToLower();
            if (Request.Form["Description"] != null && Request.Form["Description"] != "")
            {
                i.Description = Request.Form["Description"].Substring(0, 1).ToUpper() + Request.Form["Description"].Substring(1);
            }
            string Price = Request.Form["Price"];

            if (Price.IndexOf(".") >= 0)
            {
                Price = Price.Replace('.', ',');
            }
            if (Price == "" || !(Double.TryParse(Price, out double ass)))
            {
                i.Price = 0;
            }
            else if (Convert.ToDouble(Price) > 6)
            {
                return(Json("! Согласно условиям работы сайта, стоимость изображения не может превышать 6$."));
            }
            else
            {
                i.Price = Convert.ToDouble(Price);
            }
            i.ApplicationUserId = User.Identity.GetUserId();
            i.Date    = DateTime.Now;
            i.Colors  = Request.Form["Colors"].ToLower();
            i.IsBlack = Convert.ToBoolean(Request.Form["IsBlack"]);
            i.Orient  = Request.Form["Orient"];

            new ImageHandler().UploadImage(Request.Files, i);

            return(Json("Изображения успешно загружены"));
        }
示例#3
0
        public void UploadImage(System.Web.HttpFileCollectionBase files, Racoonogram.Models.Image i)
        {
            string fullPath = GetServerPath("~/Content/Content-image/");

            foreach (string file in files)
            {
                var upload = files[file];
                if (upload != null)
                {
                    System.Drawing.Image  waterMarkIm;
                    System.Drawing.Bitmap bit;
                    try
                    {
                        //get filename
                        string fileName = System.IO.Path.GetFileName(upload.FileName);
                        //save file
                        string fullPathName = GetServerPath("~/Content/MidTerm/") + fileName;
                        upload.SaveAs(fullPathName);
                        new ImageService().AddImage(i);
                        string newName = fullPath + i.ImageId + ".jpg";
                        if (System.IO.File.Exists(newName))
                        {
                            System.IO.File.Delete(newName);
                        }

                        System.Drawing.Image imNormal = System.Drawing.Image.FromFile(fullPathName);
                        imNormal.Save(newName);

                        imNormal = new ImageHandler().ResizeImage(imNormal, 1920, 1920);

                        /*ДОБАВЛЕНИЕ ВОДЯНОГО ЗНАКА*/
                        if (imNormal.Width > imNormal.Height)
                        {
                            waterMarkIm = System.Drawing.Image.FromFile(GetServerPath("~/Content/Images/") + "Watermark_.png");
                        }
                        else if (imNormal.Width < imNormal.Height)
                        {
                            waterMarkIm = System.Drawing.Image.FromFile(GetServerPath("~/Content/Images/") + "Watermark__.png");
                        }
                        else
                        {
                            waterMarkIm = System.Drawing.Image.FromFile(GetServerPath("~/Content/Images/") + "Watermark___.png");
                        }
                        int h = imNormal.Height;
                        int w = imNormal.Width;
                        bit = new Bitmap(w, h);
                        using (Graphics g = Graphics.FromImage(bit))
                        {
                            g.DrawImage(imNormal, 0, 0, w, h);
                            g.DrawImage(waterMarkIm, 10, ((imNormal.Height - waterMarkIm.Height) / 2), waterMarkIm.Width, waterMarkIm.Height);
                        }

                        bit.Save(fullPath + i.ImageId + "_normal.jpg");

                        System.Drawing.Image imNormalSmall = new ImageHandler().ResizeImage(bit, 400, 240);
                        imNormalSmall.Save(fullPath + i.ImageId + "_sm.jpg");

                        imNormalSmall = new ImageHandler().ResizeImage(imNormalSmall, 200, 40);
                        imNormalSmall.Save(fullPath + i.ImageId + "_xs.jpg");
                        imNormal = null;
                        System.IO.File.Delete(fullPathName);
                    }
                    catch (Exception ex)
                    {
                        string exeption = ex.Message;
                    }
                }
            }
        }