public void DeleteImage(int id, int imageid)
        {
            media_repo image = ActiveRecordBase <media_repo> .Find(imageid);

            advertisement advertisement = ActiveRecordBase <advertisement> .Find(id);

            advertisement.Images.Remove(image);
            ActiveRecordMediator <advertisement> .Save(advertisement);

            CancelLayout();
            RenderText("true");
        }
예제 #2
0
        public static bool smushit(int id, string image_name, String mimeType)
        {
            // sent file to yahoo
            string url = "http://www.smushit.com/ysmush.it/ws.php?";// "http://www.smushit.com/ysmush.it/ws.php?";

            log.Info("trying smushit" + image_name);
            //reset the .ext file name
            media_repo image = ActiveRecordBase <media_repo> .Find(id);

            string orgFile = image_name;

            image_name = Regex.Replace(image_name, ".ext", "." + image.ext, RegexOptions.IgnoreCase);

            File.Copy(orgFile, image_name, true);

            NameValueCollection nvc = new NameValueCollection();
            //nvc.Add("id", "TTR");
            //nvc.Add("btn-submit-photo", "Upload");
            string yurl = "";

            try {
                String  responseData = HttpUploadFile(url, image_name, "files", mimeFinder(image.ext), nvc);
                JObject obj          = JObject.Parse(responseData);
                yurl = (string)obj["dest"]; // what is the path?
            } catch {
            }
            if (!String.IsNullOrEmpty(yurl))
            {
                log.Info("did smushit" + yurl);
                byte[] imagebytes = DownloadBinary(yurl);
                ByteArrayToFile(image_name, imagebytes);
                File.Copy(image_name, orgFile, true);// overwirte the .ext with the new file.
                //File.Delete(image_name);
                deleteTmpIamges(image_name);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        public void Update([ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] users user,
                           [ARDataBind("image", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] media_repo image,
                           HttpPostedFile newimage,
                           int[] Sections, string apply, string cancel)
        {
            if (cancel != null)
            {
                RedirectToAction("list");
                return;
            }


            if (cancel != null)
            {
                RedirectToAction("list");
                return;
            }
            if (user.groups.id <= 0)
            {
                List <AbstractCriterion> baseEx = new List <AbstractCriterion>();
                baseEx.Add(Expression.Eq("default", true));
                user.groups = ActiveRecordBase <user_groups> .FindFirst(baseEx.ToArray());
            }

            /*
             * author.place_types.Clear();
             * foreach (int section in Sections)
             * {
             *  place_types tmp=ActiveRecordBase<place_types>.Find(section);
             *  if (!author.place_types.Contains(tmp) && tmp.id > 0)
             *  {
             *      author.place_types.Add(tmp);
             *  }
             * }
             *
             * user.media.Clear();
             *
             * try {
             *
             * } catch (Exception ex) {
             *  Flash["error"] = ex.Message;
             *  Flash["author"] = user;
             * }*/

            ActiveRecordMediator <users> .Save(user);

            /*
             *  ActiveRecordMediator<media_repo>.Save(image);
             *  if (newimage.ContentLength != 0)
             *  {
             *      String Fname = System.IO.Path.GetFileName(newimage.FileName);
             *      String[] fileparts = Fname.Split('.');
             *      if (String.IsNullOrEmpty(image.file_name))
             *      {
             *          image.file_name = fileparts[0];
             *      }
             *      image.ext = fileparts[1];
             *
             *      //set up the image up from the stream
             *      System.Drawing.Image processed_image = System.Drawing.Image.FromStream(newimage.InputStream);
             *
             *      // a var for uploads will start here
             *      String uploadPath = Context.ApplicationPhysicalPath + @"\uploads\mugshots\";
             *
             *      if (!HelperService.DirExists(uploadPath))
             *      {
             *          System.IO.Directory.CreateDirectory(uploadPath);
             *      }
             *      string newFile = uploadPath + image.id + ".ext";
             *      //helperService.ResizeImage(newimage, uploadPath + image.id + ".ext", 1000, 1000, true);
             *      imageService.process(image.id, processed_image, newFile, ImageService.imageMethod.Constrain, 0, 0, 1000, ImageService.Dimensions.Width, true, "", image.ext);
             *
             *      ActiveRecordMediator<media_repo>.Save(image);
             *      author.media.Add(image);
             *  }
             */
            RedirectToAction("list");
        }