Esempio n. 1
0
        public ActionResult UploadImgSlider(web_vangia_silde web_vangia_silde)
        {
            var t    = web_vangia_silde.vangia_img_silde == null ? "" : web_vangia_silde.vangia_img_silde;
            var file = t.Replace("data:image/png;base64,", "");

            if (!String.IsNullOrEmpty(file))
            {
                var    photoBytes = Convert.FromBase64String(file);
                string format     = "jpg";


                var settings = new ResizeSettings();
                settings.Scale  = ScaleMode.DownscaleOnly;
                settings.Format = format;

                //string uploadFolder = picture.DirectoryPhysical;

                string path = Server.MapPath("~/fileUpload/") + DateTime.Now.Day + DateTime.Now.Month + "/";
                // check for directory
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                var picture = new VanGiaPicture
                {
                    tblPicture = new tblSysPicture {
                        advert_id = 0, angleType = 0, cms_sql_id = 0, converted = DateTime.Now, tocheck = true, type_id = 1, title = "", position = 1
                    }
                };
                if (picture.GetConvertedFileName() == null || string.IsNullOrWhiteSpace(picture.GetConvertedFileName()))
                {
                    picture.SetFileName(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + "_" + picture.CreateFilename() + "_{0}." + format);
                }

                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Large) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Large);
                    settings.MaxWidth  = 1920;
                    settings.MaxHeight = 1200;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    web_vangia_silde.vangia_img_silde = picture.GetFilePath(VanGiaPicture.PictureSize.Large);
                }
                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Medium) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Medium);
                    settings.MaxWidth  = 130;
                    settings.MaxHeight = 130;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                }
                return(Json(new { result = web_vangia_silde.vangia_img_silde }));
            }
            else
            {
                var data = db.web_vangia_silde.Where(x => x.vangia_id_silde == web_vangia_silde.vangia_id_silde).FirstOrDefault();
                return(Json(new { result = data.vangia_img_silde }));
            }
        }
Esempio n. 2
0
        public void SaveImg(VanGiaPicture projectPicture)
        {
            var    t          = projectPicture.cfile == null ? "" : projectPicture.cfile;
            var    file       = t.Replace("data:image/png;base64,", "");
            var    photoBytes = Convert.FromBase64String(file);
            string format     = "jpg";

            if (projectPicture.isactive == 1)
            {
                projectPicture.isactive = 1;
            }
            else
            {
                projectPicture.isactive = 2;
            }
            var picture = new VanGiaPicture
            {
                tblPicture = new tblSysPicture {
                    advert_id = projectPicture.idProducts, angleType = 0, cms_sql_id = 0, converted = DateTime.Now, tocheck = true, type_id = 1, title = projectPicture.nameImg, position = projectPicture.isactive
                }
            };

            if (projectPicture.idpicture == 0)
            {
                var settings = new ResizeSettings();
                settings.Scale  = ScaleMode.DownscaleOnly;
                settings.Format = format;

                //string uploadFolder = picture.DirectoryPhysical;

                string path = Server.MapPath("~/fileUpload/") + DateTime.Now.Day + DateTime.Now.Month + "/";
                // check for directory
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                // filename with placeholder for size
                if (picture.GetConvertedFileName() == null || string.IsNullOrWhiteSpace(picture.GetConvertedFileName()))
                {
                    picture.SetFileName(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + "_" + picture.CreateFilename() + "_{0}." + format);
                }

                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Large) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Large);
                    settings.MaxWidth  = 1920;
                    settings.MaxHeight = 1200;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(VanGiaPicture.PictureSize.Large);
                    }
                }

                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Medium) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Medium);
                    settings.MaxWidth  = 130;
                    settings.MaxHeight = 130;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(VanGiaPicture.PictureSize.Medium);
                    }
                }
                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Tiny) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Tiny);
                    settings.MaxWidth  = 1500;
                    settings.MaxHeight = 600;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(VanGiaPicture.PictureSize.Tiny);
                    }
                }

                if (picture.GetFilePathPhysical(VanGiaPicture.PictureSize.Small) != null)
                {
                    string dest = path + picture.FileName(VanGiaPicture.PictureSize.Small);
                    settings.MaxWidth  = 600;
                    settings.MaxHeight = 300;
                    if (picture.WaterMarkLarge == VanGiaPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(VanGiaPicture.PictureSize.Small);
                    }
                }
                db.tblSysPictures.Add(picture.tblPicture);
                db.SaveChanges();
            }
            if (projectPicture.idpicture > 0)
            {
                tblSysPicture tblpict = db.tblSysPictures.Find(projectPicture.idpicture);
                tblpict.title           = projectPicture.nameImg;
                tblpict.position        = projectPicture.isactive;
                db.Entry(tblpict).State = EntityState.Modified;
                db.SaveChanges();
                RedirectToAction("Index", "Travel");
            }
        }