private JsonResult PostFileFunction(HttpPostedFileBase file, string contentType = "")
        {
            if (!_orchardServices.Authorizer.Authorize(mlib.Permissions.ImportMediaContent))
            {
                return(Json(_utilsServices.GetResponse(ResponseType.UnAuthorized)));
            }
            Int32  output     = 0;
            string LinkFile   = "/Media/" + _settings.Name + "/Upload";
            string pathString = Server.MapPath("~/Media/" + _settings.Name) + @"\Upload" + (contentType != "" ? "\\" + contentType : "");

            VerificaPath(pathString);
            string nomefile = System.IO.Path.GetFileName(file.FileName);

            if (_contentExtensionsServices.FileAllowed(nomefile))
            {
                int    contatore = 0;
                string cont      = "";
                while (System.IO.File.Exists(System.IO.Path.Combine(pathString, cont + nomefile)))
                {
                    contatore++;
                    cont = contatore.ToString() + "_";
                }
                // file.SaveAs(System.IO.Path.Combine(pathString, cont + nomefile));

                //    var CIimage = _orchardServices.ContentManager.New("Image");
                MediaPart mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, Path.GetFullPath(pathString).Replace(Server.MapPath("~/Media/" + _settings.Name + "/"), ""), cont + nomefile);
                // CIimage.As<MediaPart>()= mediaPart;
                var CIimage = _orchardServices.ContentManager.New(mediaPart.ContentItem.ContentType);
                _orchardServices.ContentManager.Create(mediaPart.ContentItem, VersionOptions.Published);
                //          filelist.ElencoUrl.Add(mediaPart.ContentItem.As<MediaPart>().Id);
                output = mediaPart.Id;
            }
            return(Json(new { Id = output }));
        }
        public ActionResult Upload(string folderPath, string type)
        {
            var statuses = new List <object>();

            // Loop through each file in the request
            for (int i = 0; i < HttpContext.Request.Files.Count; i++)
            {
                // Pointer to file
                var file     = HttpContext.Request.Files[i];
                var filename = Path.GetFileName(file.FileName);

                // if the file has been pasted, provide a default name
                if (file.ContentType.Equals("image/png", StringComparison.InvariantCultureIgnoreCase) && !filename.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename = "clipboard.png";
                }

                var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type);
                _contentManager.Create(mediaPart);

                statuses.Add(new {
                    id       = mediaPart.Id,
                    name     = mediaPart.Title,
                    type     = mediaPart.MimeType,
                    size     = file.ContentLength,
                    progress = 1.0,
                    url      = mediaPart.FileName,
                });
            }

            // Return JSON
            return(Json(statuses, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public ActionResult ImagePost(string folderPath, string type, string url)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission.
            var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();

            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                var buffer = new WebClient().DownloadData(url);
                var stream = new MemoryStream(buffer);

                var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url), type);
                _contentManager.Create(mediaPart);

                return(new JsonResult {
                    Data = new { folderPath, MediaPath = mediaPart.FileName }
                });
            }
            catch (Exception e) {
                return(new JsonResult {
                    Data = new { error = e.Message }
                });
            }
        }
Ejemplo n.º 4
0
        public ActionResult Upload(string folderPath)
        {
            var statuses = new List <object>();

            // Loop through each file in the request
            for (int i = 0; i < HttpContext.Request.Files.Count; i++)
            {
                // Pointer to file
                var file     = HttpContext.Request.Files[i];
                var filename = Path.GetFileName(file.FileName);

                // if the file has been pasted, provide a default name
                if (filename == "blob")
                {
                    filename = "clipboard.png";
                }

                var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename);

                statuses.Add(new {
                    id       = mediaPart.Id,
                    name     = mediaPart.Title,
                    type     = mediaPart.MimeType,
                    size     = file.ContentLength,
                    progress = 1.0,
                    url      = mediaPart.FileName,
                });
            }

            // Return JSON
            return(Json(statuses, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public ActionResult Upload(string folderPath, string type)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Cannot manage media")))
            {
                return(new HttpUnauthorizedResult());
            }

            var statuses          = new List <object>();
            var settings          = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();
            var allowedExtensions = (settings.UploadAllowedFileTypeWhitelist ?? "")
                                    .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Where(x => x.StartsWith("."));

            // Loop through each file in the request
            for (int i = 0; i < HttpContext.Request.Files.Count; i++)
            {
                // Pointer to file
                var file     = HttpContext.Request.Files[i];
                var filename = Path.GetFileName(file.FileName);

                // if the file has been pasted, provide a default name
                if (file.ContentType.Equals("image/png", StringComparison.InvariantCultureIgnoreCase) && !filename.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename = "clipboard.png";
                }

                // skip file if the allowed extensions is defined and doesn't match
                if (allowedExtensions.Any())
                {
                    if (!allowedExtensions.Any(e => filename.EndsWith(e, StringComparison.OrdinalIgnoreCase)))
                    {
                        statuses.Add(new {
                            error    = T("This file type is not allowed: {0}", Path.GetExtension(filename)).Text,
                            progress = 1.0,
                        });
                        continue;
                    }
                }

                var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type);
                Services.ContentManager.Create(mediaPart);

                statuses.Add(new {
                    id       = mediaPart.Id,
                    name     = mediaPart.Title,
                    type     = mediaPart.MimeType,
                    size     = file.ContentLength,
                    progress = 1.0,
                    url      = mediaPart.FileName,
                });
            }

            // Return JSON
            return(Json(statuses, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file,
            UrlHelper url)
        {
            List <LocalizedString> validationErrors;
            var user = _membershipService.ValidateUser(userName, password, out validationErrors);

            if (!_authorizationService.TryCheckAccess(Permissions.ManageOwnMedia, user, null) &&
                !_authorizationService.TryCheckAccess(Permissions.EditMediaContent, user, null))
            {
                throw new OrchardCoreException(T("Access denied"));
            }

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            string directoryName = Path.GetDirectoryName(name);

            if (string.IsNullOrWhiteSpace(directoryName))   // Some clients only pass in a name path that does not contain a directory component.
            {
                directoryName = "media";
            }

            // If the user only has access to his own folder, rewrite the folder name
            if (!_authorizationService.TryCheckAccess(Permissions.EditMediaContent, user, null))
            {
                directoryName = Path.Combine(_mediaLibraryService.GetRootedFolderPath(directoryName));
            }

            try {
                // delete the file if it already exists, e.g. an updated image in a blog post
                // it's safe to delete the file as each content item gets a specific folder
                _mediaLibraryService.DeleteFile(directoryName, Path.GetFileName(name));
            }
            catch {
                // current way to delete a file if it exists
            }

            string publicUrl = _mediaLibraryService.UploadMediaFile(directoryName, Path.GetFileName(name), bits);
            var    mediaPart = _mediaLibraryService.ImportMedia(directoryName, Path.GetFileName(name));

            try {
                _contentManager.Create(mediaPart);
            }
            catch {
            }

            return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                   .Set("file", publicUrl)
                   .Set("url", url.MakeAbsolute(publicUrl))
                   .Set("type", file.Optional <string>("type")));
        }
Ejemplo n.º 7
0
        public ActionResult Import(string folderPath, string type, string url)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var settings          = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();
            var allowedExtensions = (settings.UploadAllowedFileTypeWhitelist ?? "")
                                    .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Where(x => x.StartsWith("."));

            try {
                var filename = Path.GetFileName(url);

                // skip file if the allowed extensions is defined and doesn't match
                if (allowedExtensions.Any())
                {
                    if (!allowedExtensions.Any(e => filename.EndsWith(e, StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new Exception(T("This file type is not allowed: {0}", Path.GetExtension(filename)).Text);
                    }
                }

                var buffer = new WebClient().DownloadData(url);
                var stream = new MemoryStream(buffer);

                var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, filename, type);
                _contentManager.Create(mediaPart);

                return(new JsonResult {
                    Data = new { folderPath, MediaPath = mediaPart.FileName }
                });
            }
            catch (Exception e) {
                return(new JsonResult {
                    Data = new { error = e.Message }
                });
            }
        }
Ejemplo n.º 8
0
        public JsonResult ImagePost(string folderPath, string url)
        {
            try {
                var buffer    = new WebClient().DownloadData(url);
                var stream    = new MemoryStream(buffer);
                var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url));

                return(new JsonResult {
                    Data = new { folderPath, MediaPath = mediaPart.FileName }
                });
            }
            catch (Exception e) {
                return(new JsonResult {
                    Data = new { error = e.Message }
                });
            }
        }
        public ActionResult Add(int ContactFormID)
        {
            var model = new FileUploadModel
            {
                ParentID  = ContactFormID,
                MediaData = null
            };

            if (Request != null)
            {
                if (Request.Files.Count > 0)
                {
                    if (string.IsNullOrWhiteSpace(Path.GetFileName(Request.Files[0].FileName)))
                    {
                        _notifier.Error(T("Please select a file."));
                    }
                    else
                    {
                        ContactFormRecord contactForm = _contactFormService.GetContactForm(ContactFormID);

                        var folderPath = contactForm.PathUpload;
                        for (int i = 0; i < Request.Files.Count; i++)
                        {
                            var file     = Request.Files[i];
                            var filename = Path.GetFileName(file.FileName);

                            if (_contactFormService.FileAllowed(filename))
                            {
                                var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename);
                                _contentManager.Create(mediaPart);
                                var fullPart = _contentManager.Get(mediaPart.Id).As <MediaPart>();
                                model.MediaData = fullPart;
                            }
                            else
                            {
                                _notifier.Error(T("The file extension in the filename is not allowed or has not been provided."));
                            }
                        }
                    }
                }
            }

            return(View(model));
        }
        public ActionResult Upload(string folderPath, string path, string name)
        {
            var client = _dropbox.GetClient(_orchard.WorkContext.CurrentUser);

            if (client == null)
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                var file = client.GetFile(path);
                _media.ImportMedia(new MemoryStream(file), folderPath, name);
                return(Json(new { status = "ok" }));
            }
            catch (DropboxException dbe) {
                Logger.Error(dbe, "{0}, {1}", dbe.StatusCode, dbe.Response.ErrorMessage);
                return(new HttpNotFoundResult());
            }
        }
        public ActionResult Import(string folderPath, string type, string url)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var settings = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();

            try {
                var filename = Path.GetFileName(url);

                // skip file if the allowed extensions is defined and doesn't match
                if (!settings.IsFileAllowed(filename))
                {
                    throw new Exception(T("This file is not allowed: {0}", filename).Text);
                }

                var buffer = new WebClient().DownloadData(url);
                var stream = new MemoryStream(buffer);

                var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, filename, type);
                _contentManager.Create(mediaPart);

                return(new JsonResult {
                    Data = new { folderPath, MediaPath = mediaPart.FileName }
                });
            }
            catch (Exception e) {
                return(new JsonResult {
                    Data = new { error = e.Message }
                });
            }
        }
Ejemplo n.º 12
0
        public ActionResult Media()
        {
            if (Request.Files.Count == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var model = new MediaResultViewModel();

            foreach (string fileName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[fileName];
                var media = _mediaLibraryService.ImportMedia(file.InputStream, GetMediaPath(), file.FileName);
                _orchardServices.ContentManager.Create(media);

                model.files.Add(new {
                    url = _mediaLibraryService.GetMediaPublicUrl(media.FolderPath, media.FileName)
                });
            }

            return(Json(model));
        }
Ejemplo n.º 13
0
        protected override DriverResult Editor(ContentPart part, MediaLibraryUploadField field, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new MediaLibraryUploadFieldViewModel {
                SelectedIds = string.Join(",", field.Ids)
            };
            var settings = field.PartFieldDefinition.Settings.GetModel <MediaLibraryUploadFieldSettings>();

            if (updater.TryUpdateModel(model, GetPrefix(field, part), null, null))
            {
                field.Ids = String.IsNullOrEmpty(model.SelectedIds) ? new int[0] : model.SelectedIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                var files             = ((Controller)updater).Request.Files;
                var mediaPartsCreated = new List <MediaPart>();
                for (int i = 0; i < files.Count; i++)
                {
                    // To make sure that we only process those files that are uploaded using this field's UI control.
                    if (files.AllKeys[i].Equals(string.Format("MediaLibraryUploadField-{0}-{1}[]", part.PartDefinition.Name, field.Name)))
                    {
                        var file = files[i];

                        if (file.ContentLength == 0)
                        {
                            continue;
                        }

                        var allowedExtensions = (settings.AllowedExtensions ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => string.Format(".{0}", s));
                        if (allowedExtensions.Any() && !allowedExtensions.Contains(Path.GetExtension(file.FileName).ToLowerInvariant()))
                        {
                            _notifier.Warning(T("The file \"{0}\" was not uploaded, because its extension is not among the accepted ones. The accepted file extensions are: {1}.",
                                                file.FileName, string.Join(", ", allowedExtensions)));
                            continue;
                        }

                        if (settings.MaximumSizeKB > 0 && file.ContentLength > settings.MaximumSizeKB * 1024)
                        {
                            _notifier.Warning(T("The file \"{0}\" was not uploaded, because its size exceeds the {1} KB limitation.", file.FileName, settings.MaximumSizeKB));
                            continue;
                        }

                        // Checking against image-specific settings.
                        if (MimeAssistant.GetMimeType(file.FileName.ToLowerInvariant()).StartsWith("image"))
                        {
                            using (var image = Image.FromStream(file.InputStream))
                            {
                                if ((settings.ImageMaximumWidth > 0 && image.Width > settings.ImageMaximumWidth) || (settings.ImageMaximumHeight > 0 && image.Height > settings.ImageMaximumHeight))
                                {
                                    _notifier.Warning(T("The image \"{0}\" was not uploaded, because its dimensions exceed the limitations. The maximum allowed file dimensions are {1}x{2} pixels.",
                                                        file.FileName, settings.ImageMaximumWidth, settings.ImageMaximumHeight));
                                    continue;
                                }
                            }

                            file.InputStream.Position = 0;
                        }

                        // At this point we can be sure that the files comply with the settings and limitations, so we can import them.
                        var user       = _wca.GetContext().CurrentUser;
                        var folderPath = _tokenizer.Replace(settings.FolderPath, new Dictionary <string, object>
                        {
                            { "Content", part.ContentItem },
                            { "User", user }
                        });

                        folderPath = string.IsNullOrEmpty(folderPath) ? "UserUploads/" + user.Id : folderPath;

                        var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, file.FileName);
                        _contentManager.Create(mediaPart);
                        mediaPartsCreated.Add(mediaPart);
                    }
                }

                if (mediaPartsCreated.Any())
                {
                    field.Ids = field.Ids.Union(mediaPartsCreated.Select(m => m.ContentItem.Id)).ToArray();
                    _notifier.Information(T("The following items were successfully uploaded: {0}.", string.Join(", ", mediaPartsCreated.Select(mp => mp.FileName))));
                }
            }

            if (settings.Required && field.Ids.Length == 0)
            {
                updater.AddModelError("Id", T("You need to have or upload at least one file for the field {0}.", field.Name.CamelFriendly()));
            }

            return(Editor(part, field, shapeHelper));
        }
        public ActionResult Upload(string folderPath, string type)
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(om.Permissions.ImportMediaContent, folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var statuses = new List <object>();
            var settings = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();

            // Loop through each file in the request
            for (int i = 0; i < HttpContext.Request.Files.Count; i++)
            {
                // Pointer to file
                var file     = HttpContext.Request.Files[i];
                var filename = Path.GetFileName(file.FileName);

                // if the file has been pasted, provide a default name
                if (file.ContentType.Equals("image/png", StringComparison.InvariantCultureIgnoreCase) && !filename.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename = "clipboard.png";
                }

                // skip file if the allowed extensions is defined and doesn't match
                if (!settings.IsFileAllowed(filename))
                {
                    statuses.Add(new
                    {
                        error    = T("This file is not allowed: {0}", filename).Text,
                        progress = 1.0,
                    });
                    continue;
                }

                try
                {
                    var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type);
                    Services.ContentManager.Create(mediaPart);

                    statuses.Add(new
                    {
                        id       = mediaPart.Id,
                        name     = mediaPart.Title,
                        type     = mediaPart.MimeType,
                        size     = file.ContentLength,
                        progress = 1.0,
                        url      = mediaPart.FileName,
                    });
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Unexpected exception when uploading a media.");
                    statuses.Add(new
                    {
                        error    = T(ex.Message).Text,
                        progress = 1.0,
                    });
                }
            }

            // Return JSON
            return(Json(statuses, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
        public override void Validated(FormValidatedEventContext context)
        {
            if (!context.ModelState.IsValid)
            {
                //Clean up on validation fail
                foreach (var element in context.Form.Elements.Flatten())
                {
                    if (element is FileField)
                    {
                        var fileFieldElement = element as FileField;
                        if (fileFieldElement == null)
                        {
                            continue;
                        }

                        var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);
                        if (postedFileValue == null)
                        {
                            continue;
                        }

                        var postedFiles = (HttpPostedFileBase[])postedFileValue.RawValue;
                        if (postedFiles == null && postedFiles.Length != 1)
                        {
                            continue;
                        }

                        var filePath = context.Values[fileFieldElement.Name];
                        if (string.IsNullOrWhiteSpace(filePath))
                        {
                            continue;
                        }

                        _mediaLibraryService.DeleteFile(
                            Path.GetDirectoryName(filePath),
                            Path.GetFileName(filePath));
                    }
                }
            }
            else
            {
                foreach (var element in context.Form.Elements.Flatten())
                {
                    var fileFieldElement = element as FileField;
                    if (fileFieldElement == null)
                    {
                        continue;
                    }

                    var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);
                    if (postedFileValue == null)
                    {
                        continue;
                    }

                    var postedFiles = (HttpPostedFileBase[])postedFileValue.RawValue;
                    if (postedFiles == null && postedFiles.Length != 1)
                    {
                        continue;
                    }

                    var filePath = context.Values[fileFieldElement.Name];
                    if (string.IsNullOrWhiteSpace(filePath))
                    {
                        continue;
                    }

                    var mediaPart = _mediaLibraryService.ImportMedia(
                        Path.GetDirectoryName(filePath),
                        Path.GetFileName(filePath));
                    _contentManager.Create(mediaPart);
                }
            }
        }
        private string importCategory(Newtonsoft.Json.Linq.JToken item, string category)
        {
            string category_result;
            string poi_result    = "";
            string import_result = "";

            Dictionary <dynamic, dynamic> CategoryDictionary = new Dictionary <dynamic, dynamic>();
            Dictionary <dynamic, dynamic> POIDictionary      = new Dictionary <dynamic, dynamic>();

            HttpWebRequest  request;
            HttpWebResponse response;

            if (category == "video-interviste")
            {
                return("Categoria " + category + " saltata!");
            }

            try {
                string URL = baseURL + item["geojson"].ToString();
                request        = (HttpWebRequest)WebRequest.Create(URL);
                request.Method = "GET";

                response = (HttpWebResponse)request.GetResponse();
                using (var streamReader = new StreamReader(response.GetResponseStream())) {
                    category_result    = streamReader.ReadToEnd();
                    CategoryDictionary = JsonConvert.DeserializeObject <Dictionary <dynamic, dynamic> >(category_result);
                }

                if (!String.IsNullOrWhiteSpace(CategoryDictionary["features"].ToString()))
                {
                    Newtonsoft.Json.Linq.JArray features = CategoryDictionary["features"];
                    URL = baseURL + "RPC2";

                    foreach (Newtonsoft.Json.Linq.JToken poi in features)
                    {
                        request             = (HttpWebRequest)WebRequest.Create(URL);
                        request.ContentType = "application/json; charset=utf-8";
                        request.Method      = "POST";

                        using (var streamWriter = new StreamWriter(request.GetRequestStream())) {
                            string json = "{\"id\":\"djangorpc\", \"method\" : \"resources.get_poi\", \"params\" : [\"" + poi["properties"]["id"].ToString() + "\"]}";

                            streamWriter.Write(json);
                            streamWriter.Flush();
                        }

                        response = (HttpWebResponse)request.GetResponse();
                        using (var streamReader = new StreamReader(response.GetResponseStream())) {
                            poi_result     = streamReader.ReadToEnd();
                            import_result += poi_result + "\n";
                            POIDictionary  = JsonConvert.DeserializeObject <Dictionary <dynamic, dynamic> >(poi_result);
                        }

                        if (!String.IsNullOrWhiteSpace(POIDictionary["result"].ToString()))
                        {
                            if ((int)POIDictionary["result"]["fields"]["status"] == 1)
                            {
                                //Creo contenuto master (la lingua di default di Orchard dev'essere impostata a "it-IT")
                                //Per la lingua di default non bisogna settare espliticamente la cultura

                                var POIItemIT = _contentManager.New("POI");

                                ((dynamic)POIItemIT).TitlePart.Title      = POIDictionary["result"]["fields"]["name_it"].ToString();
                                ((dynamic)POIItemIT).MapPart.LocationInfo = POIDictionary["result"]["fields"]["name_it"].ToString();
                                ((dynamic)POIItemIT).BodyPart.Text        = POIDictionary["result"]["fields"]["description_it"].ToString();

                                _contentManager.Create(POIItemIT);

                                TermPart termIT = _contentManager.Get <TermPart>(POITermsDictionary["it"][category]);
                                _taxonomyService.UpdateTerms(POIItemIT, new List <TermPart> {
                                    termIT
                                }, "Categoria");

                                //Creo contenuto in francese

                                var POIItemFR = _contentManager.New("POI");

                                ((dynamic)POIItemFR).TitlePart.Title      = POIDictionary["result"]["fields"]["name_fr"].ToString();
                                ((dynamic)POIItemFR).MapPart.LocationInfo = POIDictionary["result"]["fields"]["name_fr"].ToString();
                                ((dynamic)POIItemFR).BodyPart.Text        = POIDictionary["result"]["fields"]["description_fr"].ToString();

                                _contentManager.Create(POIItemFR);

                                ((LocalizationPart)((dynamic)POIItemFR).LocalizationPart).MasterContentItem = POIItemIT;
                                _localizationService.SetContentCulture(POIItemFR, "fr-FR");

                                TermPart termFR = _contentManager.Get <TermPart>(POITermsDictionary["fr"][category]);
                                _taxonomyService.UpdateTerms(POIItemFR, new List <TermPart> {
                                    termFR
                                }, "Categoria");

                                //Creo contenuto in inglese

                                var POIItemEN = _contentManager.New("POI");

                                ((dynamic)POIItemEN).TitlePart.Title      = POIDictionary["result"]["fields"]["name_en"].ToString();
                                ((dynamic)POIItemEN).MapPart.LocationInfo = POIDictionary["result"]["fields"]["name_en"].ToString();
                                ((dynamic)POIItemEN).BodyPart.Text        = POIDictionary["result"]["fields"]["description_en"].ToString();

                                _contentManager.Create(POIItemEN);

                                ((LocalizationPart)((dynamic)POIItemEN).LocalizationPart).MasterContentItem = POIItemIT;
                                _localizationService.SetContentCulture(POIItemEN, "en-US");

                                TermPart termEN = _contentManager.Get <TermPart>(POITermsDictionary["en"][category]);
                                _taxonomyService.UpdateTerms(POIItemEN, new List <TermPart> {
                                    termEN
                                }, "Categoria");

                                //Aggiungo coordinate a mappa

                                string[] coordinates = POIDictionary["result"]["fields"]["geom"].ToString().Replace("POINT (", "").Replace(")", "").Split(null);

                                ((dynamic)POIItemIT).MapPart.Longitude = float.Parse(coordinates[0], CultureInfo.InvariantCulture.NumberFormat);
                                ((dynamic)POIItemIT).MapPart.Latitude  = float.Parse(coordinates[1], CultureInfo.InvariantCulture.NumberFormat);

                                ((dynamic)POIItemFR).MapPart.Longitude = float.Parse(coordinates[0], CultureInfo.InvariantCulture.NumberFormat);
                                ((dynamic)POIItemFR).MapPart.Latitude  = float.Parse(coordinates[1], CultureInfo.InvariantCulture.NumberFormat);

                                ((dynamic)POIItemEN).MapPart.Longitude = float.Parse(coordinates[0], CultureInfo.InvariantCulture.NumberFormat);
                                ((dynamic)POIItemEN).MapPart.Latitude  = float.Parse(coordinates[1], CultureInfo.InvariantCulture.NumberFormat);

                                //Aggiungo immagine

                                string imageUrl   = POIDictionary["result"]["fields"]["image_url"].ToString();
                                var    webClient  = new WebClient();
                                byte[] imageBytes = webClient.DownloadData(imageUrl);
                                var    mediaPart  = _mediaLibraryService.ImportMedia(new MemoryStream(imageBytes), "POI", imageUrl.Split('/').Last());
                                _contentManager.Create(mediaPart);

                                ((dynamic)POIItemIT).POI.Gallery.Ids = new Int32[] { mediaPart.Id };
                                ((dynamic)POIItemFR).POI.Gallery.Ids = new Int32[] { mediaPart.Id };
                                ((dynamic)POIItemEN).POI.Gallery.Ids = new Int32[] { mediaPart.Id };
                            }
                        }
                    }
                }

                // Disposing items
                CategoryDictionary = null;
                POIDictionary      = null;
                request            = null;
                response           = null;

                return(import_result);
            } catch (Exception e) {
                return(e.Message);
            }
        }