Ejemplo n.º 1
0
 /// <summary>
 /// To delete the record.
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 public APIResponse Delete()
 {
     if (EntityId == null)
     {
         throw new ZCRMException("Entity ID MUST NOT be NULL for Delete Operation");
     }
     return(EntityAPIHandler.GetInstance(this).DeleteRecord());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// To create the record.
 /// </summary>
 /// <returns>APIResponse class instance</returns>
 public APIResponse Create()
 {
     if (EntityId != null)
     {
         throw new ZCRMException("Entity ID MUST be NUL for Create Operation");
     }
     return(EntityAPIHandler.GetInstance(this).CreateRecord());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// To update the record.
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 public APIResponse Update()
 {
     if (EntityId == null)
     {
         throw new ZCRMException("Entity ID MUST NOT be NULl for update operation");
     }
     return(EntityAPIHandler.GetInstance(this).UpdateRecord());
 }
Ejemplo n.º 4
0
        public BulkAPIResponse <ZCRMRecord> GetRecords(long?cvId, string sortByField, CommonUtil.SortOrder?sortOrder, int page, int perPage, string modifiedSince, string isConverted, string isApproved, List <string> fields)
        {
            requestMethod = APIConstants.RequestMethod.GET;
            urlPath       = module.ApiName;
            if (cvId != null)
            {
                requestQueryParams.Add("cvid", cvId.ToString());
            }
            if (sortByField != null)
            {
                requestQueryParams.Add("sort_by", sortByField);
            }
            if (sortOrder != null)
            {
                requestQueryParams.Add("sort_order", sortOrder.ToString());
            }
            requestQueryParams.Add(APIConstants.PAGE, page.ToString());
            requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
            if (isApproved != null && isApproved != "")
            {
                requestQueryParams.Add("approved", isApproved);
            }
            if (isConverted != null && isConverted != "")
            {
                requestQueryParams.Add("converted", isConverted);
            }
            if (fields != null)
            {
                requestQueryParams.Add("fields", CommonUtil.CollectionToCommaDelimitedString(fields));
            }
            if (modifiedSince != null && modifiedSince != "")
            {
                requestHeaders.Add("If-Modified-Since", modifiedSince);
            }

            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            JObject           responseJSON = response.ResponseJSON;

            if (responseJSON.ContainsKey(APIConstants.DATA))
            {
                JArray recordsArray = (JArray)responseJSON[APIConstants.DATA];
                foreach (JObject recordDetails in recordsArray)
                {
                    ZCRMRecord record = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails["id"]));
                    EntityAPIHandler.GetInstance(record).SetRecordProperties(recordDetails);
                    records.Add(record);
                }
            }
            response.BulkData = records;
            return(response);
        }
Ejemplo n.º 5
0
 public BulkAPIResponse <ZCRMRecord> RemoveTagsFromRecords(List <long> recordId, List <string> tagNames)
 {
     if (tagNames.Count > 10)
     {
         throw new ZCRMException(APIConstants.API_MAX_RECORD_TAGS_MSG);
     }
     if (recordId.Count > 100)
     {
         throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
     }
     try
     {
         string tagname = "", recordid = "";
         requestMethod = APIConstants.RequestMethod.POST;
         foreach (long id in recordId)
         {
             recordid += id + ",";
         }
         foreach (string tag in tagNames)
         {
             tagname += tag + ",";
         }
         urlPath = "" + module.ApiName + "/actions/remove_tags?ids=" + recordid + "&tag_names=" + tagname + "";
         BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();
         List <ZCRMRecord>            removetags = new List <ZCRMRecord>();
         List <EntityResponse>        responses = response.BulkEntitiesResponse;
         foreach (EntityResponse entityResponse in responses)
         {
             if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
             {
                 JObject    responseData = entityResponse.ResponseJSON;
                 JObject    tagDetails   = (JObject)responseData[APIConstants.DETAILS];
                 ZCRMRecord removeTag    = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(tagDetails["id"]));
                 EntityAPIHandler.GetInstance(removeTag).SetRecordProperties(tagDetails);
                 removetags.Add(removeTag);
                 entityResponse.Data = removeTag;
             }
             else
             {
                 entityResponse.Data = null;
             }
         }
         response.BulkData = removetags;
         return(response);
     }
     catch (Exception e) when(!(e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
Ejemplo n.º 6
0
        public BulkAPIResponse <ZCRMRecord> CreateRecords(List <ZCRMRecord> records)
        {
            if (records.Count > 100)
            {
                throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
            }
            requestMethod = APIConstants.RequestMethod.POST;
            urlPath       = module.ApiName;
            JObject requestBodyObject = new JObject();
            JArray  dataArray         = new JArray();

            foreach (ZCRMRecord record in records)
            {
                if (record.EntityId == null)
                {
                    dataArray.Add(EntityAPIHandler.GetInstance(record).GetZCRMRecordAsJSON());
                }
                else
                {
                    throw new ZCRMException("Entity ID Must be null/empty for CreateRecords operation.");
                }
            }
            requestBodyObject.Add(APIConstants.DATA, dataArray);
            requestBody = requestBodyObject;

            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord>     createdRecords = new List <ZCRMRecord>();
            List <EntityResponse> responses      = response.BulkEntitiesResponse;
            int responseSize = responses.Count;

            for (int i = 0; i < responseSize; i++)
            {
                EntityResponse entityResponse = responses[i];
                if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
                {
                    JObject    responseData  = entityResponse.ResponseJSON;
                    JObject    recordDetails = (JObject)responseData[APIConstants.DETAILS];
                    ZCRMRecord newRecord     = records[i];
                    EntityAPIHandler.GetInstance(newRecord).SetRecordProperties(recordDetails);
                    createdRecords.Add(newRecord);
                    entityResponse.Data = newRecord;
                }
                else
                {
                    entityResponse.Data = null;
                }
            }
            response.BulkData = createdRecords;
            return(response);
        }
Ejemplo n.º 7
0
        public BulkAPIResponse <ZCRMRecord> MassUpdateRecords(List <long> entityIds, string fieldAPIName, Object value)
        {
            if (entityIds.Count > 100)
            {
                throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
            }
            //NOTE: null value is not converted to JObject of type null;
            requestMethod = APIConstants.RequestMethod.PUT;
            urlPath       = module.ApiName;
            JObject requestBodyObject = new JObject();
            JArray  dataArray         = new JArray();

            foreach (long id in entityIds)
            {
                JObject updateJSON = new JObject
                {
                    { fieldAPIName, value.ToString() },
                    { "id", Convert.ToString(id) }
                };
                dataArray.Add(updateJSON);
            }
            requestBodyObject.Add(APIConstants.DATA, dataArray);
            requestBody = requestBodyObject;

            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord>     updatedRecords = new List <ZCRMRecord>();
            List <EntityResponse> responses      = response.BulkEntitiesResponse;

            foreach (EntityResponse entityResponse in responses)
            {
                if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
                {
                    JObject    responseData  = entityResponse.ResponseJSON;
                    JObject    recordDetails = (JObject)responseData[APIConstants.DETAILS];
                    ZCRMRecord updatedRecord = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails["id"]));
                    EntityAPIHandler.GetInstance(updatedRecord).SetRecordProperties(recordDetails);
                    updatedRecords.Add(updatedRecord);
                    entityResponse.Data = updatedRecord;
                }
                else
                {
                    entityResponse.Data = null;
                }
            }
            response.BulkData = updatedRecords;
            return(response);
        }
        public BulkAPIResponse <ZCRMRecord> GetRecords(string sortByField, CommonUtil.SortOrder?sortOrder, int page, int perPage, string modifiedSince)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName;
                if (sortByField != null)
                {
                    requestQueryParams.Add("sort_by", sortByField);
                }
                if (sortOrder != null)
                {
                    requestQueryParams.Add("sort_order", sortOrder.ToString());
                }
                requestQueryParams.Add(APIConstants.PAGE, page.ToString());
                requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
                if (modifiedSince != null && modifiedSince != "")
                {
                    requestHeaders.Add("If-Modified-Since", modifiedSince);
                }

                BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

                List <ZCRMRecord> recordsList  = new List <ZCRMRecord>();
                JObject           responseJSON = response.ResponseJSON;
                if (responseJSON.ContainsKey(APIConstants.DATA))
                {
                    JArray recordsArray = (JArray)responseJSON[APIConstants.DATA];
                    foreach (JObject recordDetails in recordsArray)
                    {
                        ZCRMRecord record = ZCRMRecord.GetInstance(relatedList.ApiName, Convert.ToInt64(recordDetails["id"]));
                        EntityAPIHandler.GetInstance(record).SetRecordProperties(recordDetails);
                        recordsList.Add(record);
                    }
                }
                response.BulkData = recordsList;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// To deletes the record photo.
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 public APIResponse DeletePhoto()
 {
     return(EntityAPIHandler.GetInstance(this).DeletePhoto());
 }
Ejemplo n.º 10
0
 /// <summary>
 /// To download the record photo.
 /// </summary>
 /// <returns>FileAPIResponse class instance.</returns>
 public FileAPIResponse DownloadPhoto()
 {
     return(EntityAPIHandler.GetInstance(this).DownloadPhoto());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// To upload the record photo based on file path
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 /// <param name="filePath">Upload photo file path (String)</param>
 public APIResponse UploadPhoto(string filePath)
 {
     return(EntityAPIHandler.GetInstance(this).UploadPhoto(filePath));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// To convert the record based on potential record  and ZCRMUser class instance.
 /// </summary>
 /// <returns>Dictionary(String,Long).</returns>
 /// <param name="potential">ZCRMRecord class instance</param>
 /// <param name="assignToUser">ZCRMUser class instance</param>
 public Dictionary <string, long> Convert(ZCRMRecord potential, ZCRMUser assignToUser)
 {
     return(EntityAPIHandler.GetInstance(this).ConvertRecord(potential, assignToUser));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// To get the record based on record Id of the module.
        /// </summary>
        /// <returns>APIResponse class instance.</returns>
        /// <param name="entityId">Entity(record) Id (Long) of the module</param>
        public APIResponse GetRecord(long entityId)
        {
            ZCRMRecord record = ZCRMRecord.GetInstance(ApiName, entityId);

            return(EntityAPIHandler.GetInstance(record).GetRecord());
        }