コード例 #1
0
        /// <summary>
        /// test in feedler
        /// User-Agent: Fiddler
        ///Content-Type: application/json
        ///Host: localhost
        ///Content-Length: 105
        ///Cookie: .ASPXAUTH=3BDDACF3339764AE73D8AF6A9992CE0C34247D3107C7E66561BCF0A8ACB81C0B0708A274B5B5A57B3C9425AA98825AF5429AE0DE9958CEC8923B998667D89184755E3446DAA5832C7C16C519ABDD1981E919AC22E1A81D277F615F3240264D5FB0B46F174EEC84EB839387462EA250CC71B856178CE26EF0EDEFD6B00E40FACF
        ///X-XSRF-TOKEN: Tnaq+qFFu+B/NPrfJZnTg5FoATHDCrTP3aAAXA90MiS1vpkk5y2QwfRJ5aAmqu4n7GFv+6CcUos+klKlOXBu1A==
        ///{"cpf":[424,414],"Referente":"anonio","Privacy":true,"testInput":"aaaasasas","TestNumero":633}
        /// </summary>
        /// <param name="eObj"></param>
        /// <returns></returns>
        public Response Post(ExpandoObject eObj)
        {
            if (_csrfTokenHelper.DoesCsrfTokenMatchAuthToken())
            {
                var currentUser = _orchardServices.WorkContext.CurrentUser;
                if (currentUser == null)
                {
                    return(_utilsServices.GetResponse(ResponseType.InvalidUser));
                }
                var result = _contentExtensionsServices.StoreInspectExpando(eObj, currentUser.ContentItem);

                // solleva l'evento di sincronizzazione del contact dopo l'aggiornamento del numero di telefono
                _contactEventHandler.Synchronize(currentUser);

                return(result);
            }
            else
            {
                return(_utilsServices.GetResponse(ResponseType.InvalidXSRF)); // { Message = "Invalid Token/csrfToken", Success = false, ErrorCode=ErrorCode.InvalidXSRF,ResolutionAction=ResolutionAction.Login });
            }
        }
コード例 #2
0
        private Response StoreNewContentItem(ExpandoObject eObj, ContentItem TheContentItem)
        {
            string tipoContent       = ((dynamic)eObj).ContentType;
            Int32  IdContentToModify = 0; // new content

            // NewContent.As<TitlePart>.Title = "Creazione";
            try {
                if ((Int32)(((dynamic)eObj).Id) > 0)
                {
                    IdContentToModify = (Int32)(((dynamic)eObj).Id);
                }
            }
            catch {
            }
            ContentItem NewOrModifiedContent;
            Response    rsp             = new Response();
            string      validateMessage = "";

            if (IdContentToModify > 0)
            {
                NewOrModifiedContent = _orchardServices.ContentManager.Get(IdContentToModify, VersionOptions.Latest);
                //if (NewOrModifiedContent==null){
                //    var pippo = _orchardServices.ContentManager.GetAllVersions(IdContentToModify);
                //}
                //  endif IdContentToModify).Where(x=>x.VersionRecord.Id>);
                if (!_orchardServices.Authorizer.Authorize(OrchardCore.Contents.Permissions.EditContent, NewOrModifiedContent))
                {
                    return(_utilsServices.GetResponse(ResponseType.UnAuthorized));
                }
                validateMessage = ValidateMessage(NewOrModifiedContent, "Modified");
            }
            else
            {
                NewOrModifiedContent = _orchardServices.ContentManager.New(tipoContent);
                if (!_orchardServices.Authorizer.Authorize(OrchardCore.Contents.Permissions.EditContent, NewOrModifiedContent))
                {
                    return(_utilsServices.GetResponse(ResponseType.UnAuthorized));
                }
                _orchardServices.ContentManager.Create(NewOrModifiedContent, VersionOptions.Draft);// se non faccio il create poi non vengono salvati i field
                validateMessage = ValidateMessage(NewOrModifiedContent, "Created");
            }

            if (string.IsNullOrEmpty(validateMessage))
            {
                rsp = _contentExtensionsServices.StoreInspectExpando(eObj, NewOrModifiedContent);
            }
            else
            {
                rsp = _utilsServices.GetResponse(ResponseType.None, validateMessage);
            }

            if (rsp.Success)
            {
                try {
                    string language = "";
                    try {
                        language = ((dynamic)eObj).Language;
                    }
                    catch { }
                    if (NewOrModifiedContent.As <LocalizationPart>() != null)
                    {
                        if (!string.IsNullOrEmpty(language))
                        {
                            NewOrModifiedContent.As <LocalizationPart>().Culture = _cultureManager.GetCultureByName(language);
                        }
                        NewOrModifiedContent.As <LocalizationPart>().MasterContentItem = NewOrModifiedContent;
                    }
                    validateMessage = ValidateMessage(NewOrModifiedContent, "");
                    if (string.IsNullOrEmpty(validateMessage))
                    {
                        _orchardServices.ContentManager.Create(NewOrModifiedContent, VersionOptions.DraftRequired);
                    }
                    else
                    {
                        rsp = _utilsServices.GetResponse(ResponseType.None, validateMessage);
                    }

                    // _localizationService.SetContentCulture(NewContent, language);
                    if (((dynamic)NewOrModifiedContent).AutoroutePart != null)
                    {
                        ((dynamic)NewOrModifiedContent).AutoroutePart.DisplayAlias = _autorouteService.Value.GenerateAlias(((dynamic)NewOrModifiedContent).AutoroutePart);
                        _autorouteService.Value.ProcessPath(((dynamic)NewOrModifiedContent).AutoroutePart);
                        _autorouteService.Value.PublishAlias(((dynamic)NewOrModifiedContent).AutoroutePart);
                        dynamic data = new ExpandoObject();
                        data.DisplayAlias = ((dynamic)NewOrModifiedContent).AutoroutePart.DisplayAlias;
                        rsp.Data          = data;
                    }
                    //   Handlers.Invoke(handler => handler.Updating(context), Logger);
                }
                catch (Exception ex) {
                    try {
                        _orchardServices.ContentManager.Remove(NewOrModifiedContent);
                    }
                    catch (Exception ex2) {
                        rsp = _utilsServices.GetResponse(ResponseType.None, ex2.Message);
                    }
                    rsp = _utilsServices.GetResponse(ResponseType.None, ex.Message);
                }
            }
            else
            {
                try {
                    _orchardServices.ContentManager.Remove(NewOrModifiedContent);
                }
                catch (Exception ex2) {
                    rsp = _utilsServices.GetResponse(ResponseType.None, ex2.Message);
                }
            }
            //if (this.ExternalContentCreated != null) {
            //    this.ExternalContentCreated(this, new EventArgs());
            //}

            return(rsp);
        }