Beispiel #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////


        #region Create/Add/Modify Methods
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        ///// <summary>
        ///// Create a Snippet having Owner and Creator = CurrentUser
        ///// </summary>
        //public long SaveSnippet(Snippet snippet)
        //{
        //    //Check that the client has been already logged in, and if this is not the case, automatically login:
        //    if (!CheckLogin())
        //    {
        //        SetLastError(log, "Cannot login into the system");
        //        return -1;
        //    }

        //    snippet.TargetGroupID = CurrentUser.PersonalGroupID;
        //    return CreateSnippet(snippet, CurrentUser);
        //}


        public long SaveSnippet(Snippet snippet)
        {
            if ((snippet == null) || (snippet.AreFieldsValid() != SnippetWrongField.OK))
            {
                SetLastError(log, ErrorCodes.WRONG_INPUT,
                             string.Format("Input error: snippet={0}, creator={1}", snippet.PrintNull(), CurrentUser.PrintNull()));
                return(-1);
            }

            //Check that the client has been already logged in, and if this is not the case, automatically login:
            if (!CheckLogin())
            {
                SetLastError(log, ErrorCodes.NOT_LOGGED_IN, "Cannot login into the system");
                return(-1);
            }

            //send the request and parse the response:
            string             contentToSend = "content=" + HttpUtility.UrlEncode(snippet.Serialize(m_serialFormat));
            S2CResObj <object> resp          = SendReqObj(CREATE_SNIPPET_URL, contentToSend, true);

            //build the result:
            long result = ParseLongResponse(resp);

            if (result == -1)
            {
                //check if the Status is TARGET_GROUP_INVALID:
                if ((resp != null) && (resp.Status == ErrorCodes.TARGET_GROUP_DELETED))
                {
                    return(-2);
                }
            }
            return(result);
        }