Exemple #1
0
        //TODO: Inspect the field modified_by in the response;
        //TODO: Returns ZCRMModule.. Inspect the method;
        private ZCRMModule GetZCRMModule(JObject moduleDetails)
        {
            ZCRMModule module = ZCRMModule.GetInstance(Convert.ToString(moduleDetails.GetValue("api_name")));

            module.Id            = Convert.ToInt64(moduleDetails.GetValue("id"));
            module.SystemName    = Convert.ToString(moduleDetails.GetValue("module_name"));
            module.SingularLabel = Convert.ToString(moduleDetails.GetValue("singular_label"));
            module.PluralLabel   = Convert.ToString(moduleDetails.GetValue("plural_label"));
            module.Creatable     = Convert.ToBoolean(moduleDetails.GetValue("creatable"));
            module.Viewable      = Convert.ToBoolean(moduleDetails.GetValue("viewable"));
            module.Editable      = Convert.ToBoolean(moduleDetails.GetValue("editable"));
            module.Convertible   = Convert.ToBoolean(moduleDetails.GetValue("convertible"));
            module.Deletable     = Convert.ToBoolean(moduleDetails.GetValue("deletable"));
            module.CustomModule  = Convert.ToBoolean(moduleDetails.GetValue("generated_type").ToString().Equals("custom"));

            JArray accessibleProfilesArray = (JArray)moduleDetails.GetValue("profiles");

            foreach (JObject accessibleProfiles in accessibleProfilesArray)
            {
                ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles.GetValue("id")), Convert.ToString(accessibleProfiles.GetValue("name")));
                module.AddAccessibleProfiles(profile);
            }
            Console.WriteLine(moduleDetails["modified_by"].Type == JTokenType.Null);
            if (moduleDetails["modified_by"].HasValues)
            {
                JObject  modifiedByObject = (JObject)moduleDetails.GetValue("modified_by");
                ZCRMUser modifiedUser     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), Convert.ToString(modifiedByObject.GetValue("name")));
                module.ModifiedBy   = modifiedUser;
                module.ModifiedTime = Convert.ToString(moduleDetails.GetValue("modified_time"));
            }
            if (moduleDetails.ContainsKey("related_lists"))
            {
                List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>();
                JArray relatedListsArray = (JArray)moduleDetails.GetValue("related_lists");
                foreach (JObject relatedListDetails in relatedListsArray)
                {
                    ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, Convert.ToString(relatedListDetails.GetValue("api_name)")));
                    SetRelatedListProperties(relatedList, relatedListDetails);
                    relatedLists.Add(relatedList);
                }
                module.RelatedLists = relatedLists;
            }
            if (moduleDetails.ContainsKey("business_card_fields"))
            {
                List <string> bcFields      = new List <string>();
                JArray        bcFieldsArray = (JArray)moduleDetails.GetValue("business_card_fields");
                foreach (JObject bcField in bcFieldsArray)
                {
                    bcFields.Add(bcField.ToString());
                }
                module.BussinessCardFields = bcFields;
            }
            if (moduleDetails.ContainsKey("layouts"))
            {
                module.Layouts = ModuleAPIHandler.GetInstance(module).GetAllLayouts(moduleDetails);
            }
            return(module);
        }
Exemple #2
0
        public BulkAPIResponse <ZCRMRecord> InsertIssuer(IssuerModel issuer)
        {
            // hardcode
            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            ZCRMRecord        record1      = new ZCRMRecord("accounts"); //module api name

            record1.SetFieldValue("Account_Name", issuer.UserName);
            record1.SetFieldValue("Full_Name", issuer.FullName);
            record1.SetFieldValue("Username", issuer.UserName);
            record1.SetFieldValue("Industry", "1");
            record1.SetFieldValue("Company_Name", issuer.BusinessName.ToString());
            record1.SetFieldValue("Phone", issuer.MobileNumber);
            record1.SetFieldValue("Fax", issuer.MobileNumber);
            record1.SetFieldValue("Employees", 1);
            record1.SetFieldValue("Total_Amount_Disbursed", issuer.totaldisbursed);
            record1.SetFieldValue("Last_Repayment_Date", issuer.LastRepaymentDate.Value.ToString());
            record1.SetFieldValue("Days_Overdue", issuer.daysoverdue);
            record1.SetFieldValue("Issuer_Account_Balance", issuer.ActualAmount);
            record1.SetFieldValue("Outstanding_Amount_with_Late_Fee", issuer.outamountwithlf);
            record1.SetFieldValue("Outstanding_Amount_no_Late_Fee", issuer.outamountwithoutlf);
            record1.SetFieldValue("Outstanding_Late_Fee", issuer.outstandinglf);
            record1.SetFieldValue("Total_Amount_Overdue", issuer.overdueamount);
            record1.SetFieldValue("Total_Principle_Paid", issuer.totalpaidprincipal);
            record1.SetFieldValue("Total_Interest_Paid", issuer.totalpaidinterest);
            record1.SetFieldValue("Total_Late_Fee_Paid", issuer.paidlatefees);
            record1.SetFieldValue("Total_Late_Interest_Paid", issuer.totalpaidlateinterest);
            record1.SetFieldValue("Total_Paid_Amount", issuer.TotalPaidAmount);
            record1.CreatedTime = DateTime.UtcNow.Ticks.ToString();
            records.Add(record1);


            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                       //module api name
            BulkAPIResponse <ZCRMRecord> response        = moduleIns.CreateRecords(records); //records - list of ZCRMRecord instances filled with required data for upsert.
            List <ZCRMRecord>            insertedRecords = response.BulkData;                //upsertedRecords - list of ZCRMRecord instance

            foreach (var entityID in response.BulkData)
            {
                var newID = new tbl_CheckID
                {
                    IDZoho  = entityID.EntityId,
                    EmailMS = issuer.UserName
                };
                dbzoho.tbl_CheckID.Add(newID);
                dbzoho.SaveChanges();
            }

            List <EntityResponse> entityResponses = response.BulkEntitiesResponse; //entityResponses - list of EntityResponses instance

            return(response);
        }
        public List <ZCRMRecord> Post()
        {
            //test
            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            var dbContext = new MS_DEVEntities();
            var data      = dbContext.Database.SqlQuery <InvestorModel>("select investorinfo.*,investamount.totalinvestedamount,investamount.paidP,paidI,paidLI,TotalAmountReceived,currentinFunding,numberofinvested,convert(decimal(18,2),Closeoff_PI)as Closeoff_PI,numofcloseoff,numberoffullypaidnotes,numofdelinquent,convert(decimal(18,2),outstanding_I)as outstanding_I,convert(decimal(18,2),outstanding_P)as outstanding_P,convert(decimal(18,2),outstandingPI)as outstandingPI from ( select oldinformation.*, newinformation.age, newinformation.FullName, newinformation.Gender, newinformation.Mobilenumber, newinformation.Nationality, newinformation.DateofBirth, newinformation.NRIC_Number, newinformation.PassportNumber from( select almost.*, lastlogin from( select users.*, ActualAmount from( select USER_ID, ActualAmount from tbl_Balances where User_ID is not null) as balance left join( select UserID, username, QualifiedDate, AdminVerification, DateCreated from tbl_users ) as users on balance.User_ID = users.UserID) as almost left join( select  UserName, max(timestamp) as lastlogin from tbl_AuditLog group by UserName) as pre on almost.UserName = pre.UserName) as oldinformation left join( select User_ID, FullName, Gender, DateofBirth, datediff(year, DateofBirth, getdate()) as age, NRIC_Number, PassportNumber, Mobilenumber, Nationality  from tbl_AccountDetails) as newinformation on oldinformation.UserID = newinformation.User_ID) as investorinfo left join( select totalinvested.*,paidI,paidP,paidLI,TotalAmountReceived,OfferedAmount as currentinFunding,numberofinvested,Closeoff_PI,numofcloseoff,numberoffullypaidnotes,outstanding_I,outstanding_P,outstandingPI,numofdelinquent From( select Investor_Id, sum(acceptedamount) as totalinvestedamount   from( select  OfferId, Investor_Id, case when LoanRequest_Id in (2036, 2001, 2037, 2019, 2004, 2059, 2020, 1994, 2053) then 0   else AcceptedAmount end as acceptedamount,LoanRequest_Id,case when LoanRequest_Id = 2001 then concat('2001','-',offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as a where acceptedamount<>0  group by Investor_Id) as totalinvested left join( select Investor_Id,convert(decimal(18, 2), sum(isnull(paidinterest, 0))) as paidI, convert(decimal(18, 2), sum(isnull(paidprincipal, 0))) as paidP,convert(decimal(18, 2), sum(isnull(paidlateinterest, 0))) as paidLI, convert(decimal(18, 2), sum(isnull(paidinterest, 0) + isnull(paidprincipal, 0) + isnull(paidlateinterest, 0))) as TotalAmountReceived from( select pre1.Investor_Id, pre1.AcceptedAmount, pre1.LoanRequest_Id, pre1.newcontractid, InvestorRepaymentPayment.* from( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1 ) as pre1 join InvestorRepaymentPayment on pre1.OfferId = InvestorRepaymentPayment.OfferID ) as paidamount group by Investor_Id) as totalpaidamount on totalinvested.Investor_Id = totalpaidamount.Investor_Id left join( select Investor_Id,OfferedAmount from tbl_Loanoffers join( select* from tbl_LoanRequests where LoanStatus= 2) as a on tbl_Loanoffers.LoanRequest_Id = a.RequestId) as currentfunding on totalinvested.Investor_Id = currentfunding.Investor_Id left join( select Investor_Id,count(totalinvested) as numberofinvested from( select Investor_Id, sum(acceptedamount) as totalinvested, LoanRequest_Id   from( select  OfferId, Investor_Id, case when LoanRequest_Id in (2036, 2001, 2037, 2019, 2004, 2059, 2020, 1994, 2053) then 0   else AcceptedAmount end as acceptedamount,LoanRequest_Id,case when LoanRequest_Id = 2001 then concat('2001','-',offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as a where acceptedamount<>0  group by Investor_Id,LoanRequest_Id) as final group by Investor_Id) as numberofinvest on totalinvested.Investor_Id = numberofinvest.Investor_Id left join( select Investor_Id,sum(Principal - isnull(paidprincipal, 0) + interest - isnull(paidinterest, 0)) as Closeoff_PI from( select b.*, c.Investor_Id, c.AcceptedAmount, c.newcontractid from( select a.* From( select InvestorRepayment.*, LoanRequest_Id from InvestorRepayment left join tbl_Loanoffers on InvestorRepayment.OfferID = tbl_Loanoffers.OfferId) as a  left join tbl_LoanRequests on a.LoanRequest_Id = tbl_LoanRequests.RequestId where LoanStatus = 9) as b left join( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as c on b.OfferId = c.OfferId) as d where PayStatus<>1 group by Investor_Id) as closeoffamount on totalinvested.Investor_Id = closeoffamount.Investor_Id left join( select Investor_Id, count(totalclose) as numofcloseoff from( select a.Investor_Id, sum(AcceptedAmount) as totalclose, LoanRequest_Id from( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as a left join tbl_LoanRequests on a.LoanRequest_Id = tbl_LoanRequests.RequestId where LoanStatus = 9 group by Investor_Id,LoanRequest_Id) as final group by Investor_Id) as numberofcloseoff on totalinvested.Investor_Id = numberofcloseoff.Investor_Id left join( select Investor_Id,count(amount) as numberoffullypaidnotes from( select Investor_Id, sum(acceptedamount) as amount, LoanRequest_Id from( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as a left join tbl_LoanRequests on a.LoanRequest_Id = tbl_LoanRequests.RequestId where LoanStatus = 7 group by Investor_Id,LoanRequest_Id) as final group by Investor_Id) as fully on totalinvested.Investor_Id = fully.Investor_Id left join( select Investor_Id,sum(principal - isnull(paidprincipal, 0)) as outstanding_P, sum(Interest - isnull(paidinterest, 0)) as outstanding_I, sum(principal + interest - isnull(paidprincipal, 0) - isnull(paidinterest, 0)) as outstandingPI  from( select b.*, Investor_Id from( select a.* From( select InvestorRepayment.*, LoanRequest_Id from InvestorRepayment left join tbl_Loanoffers on InvestorRepayment.OfferID = tbl_Loanoffers.OfferId) as a left join tbl_LoanRequests on a.LoanRequest_Id = tbl_LoanRequests.RequestId where LoanStatus in (3, 5, 7, 9)) as b left join( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as c on b.OfferID = c.OfferId) as final where PayStatus<>1 group by Investor_Id) as deliquentamount on totalinvested.Investor_Id = deliquentamount.Investor_Id left join( select Investor_Id,count(LoanRequest_Id) as numofdelinquent from( select Investor_Id, sum(acceptedamount) as amount, LoanRequest_Id from( select a.*, RequestId from( select  OfferId, Investor_Id, AcceptedAmount, LoanRequest_Id,case when  LoanRequest_Id = 2001 then concat('2001', '-', offerid) else ContractId end as newcontractid from tbl_Loanoffers where OfferStatus = 1) as a left join(select* from tbl_LoanRequests where LoanStatus in (3,5,9) ) as b on a.LoanRequest_Id = b.RequestId where RequestId is not null) as pre group by Investor_Id,LoanRequest_Id) as final group by Investor_Id) as numberofdelinquent on totalinvested.Investor_Id = numberofdelinquent.Investor_Id) as investamount on investorinfo.UserID = investamount.Investor_Id").ToList();
            //foreach (var rc in data)
            //{
            ZCRMRecord record1 = new ZCRMRecord("accounts"); //module api name

            record1.SetFieldValue("UserID", "rc.CompanyName");
            record1.SetFieldValue("FullName", "rc.FullName");
            record1.SetFieldValue("UserName", "rc.UserName");
            record1.SetFieldValue("Age", "rc.MobileNumber");
            record1.SetFieldValue("Gender", "rc.IssuerAccountBalance");
            record1.SetFieldValue("NRIC_Number", "rc.OverdueDate");
            record1.SetFieldValue("PassportNumber", "rc.TotalAmountDisbursed");
            record1.SetFieldValue("Nationality", "rc.TotalAmountOverdue");
            record1.SetFieldValue("DateOfBirth", "rc.OutstandingLateFee");
            record1.SetFieldValue("MobileNumber", "rc.OutstandingAmountNoLateFee");
            record1.SetFieldValue("SignUpDate", "rc.OutstandingAmountWithLateFee");
            record1.SetFieldValue("AdminVerification", "rc.LastRepaymentDate");
            record1.SetFieldValue("QualifiedDate", "rc.TotalFeesPaid");
            record1.SetFieldValue("LatestLogin", "rc.TotalPrincipalPaid");
            record1.SetFieldValue("SumOfNumInvestNotes", "rc.TotalInterestPaid");
            record1.SetFieldValue("InvestorAmount_TotalInvested", " rc.TotalLateInterestPaid");
            record1.SetFieldValue("SumOfLedgerAmount", "rc.CompanyName");
            record1.SetFieldValue("NumberOfDelinquentNote", "rc.FullName");
            record1.SetFieldValue("TotalDelinquentAmount", "rc.UserName");
            record1.SetFieldValue("NumberOfFullyPaidNote", "rc.MobileNumber");
            record1.SetFieldValue("InvestorAmount_PrincipalReceived", "rc.IssuerAccountBalance");
            record1.SetFieldValue("InvestorAmount_InvestReceived", "rc.OverdueDate");
            record1.SetFieldValue("TotalAmountReceived", "rc.TotalAmountDisbursed");
            record1.SetFieldValue("SumOftotPaidLateInterest", "rc.TotalAmountOverdue");
            record1.SetFieldValue("NumberOfCloseOffNote", "rc.OutstandingLateFee");
            record1.SetFieldValue("TotalCloseOffPandI", "rc.OutstandingAmountNoLateFee");
            record1.SetFieldValue("CurrentInFundingAmount", "rc.OutstandingAmountWithLateFee");
            record1.SetFieldValue("InvestorAmount_OutstandingP", "rc.LastRepaymentDate");
            record1.SetFieldValue("InvestorAmount_OutstandingI", "rc.TotalFeesPaid");
            records.Add(record1);
            //ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
            //BulkAPIResponse<ZCRMRecord> response = moduleIns.CreateRecords(records);
            // }
            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                       //module api name
            BulkAPIResponse <ZCRMRecord> response        = moduleIns.CreateRecords(records); //records - list of ZCRMRecord instances filled with required data for upsert.
            List <ZCRMRecord>            upsertedRecords = response.BulkData;                //upsertedRecords - list of ZCRMRecord instance
            List <EntityResponse>        entityResponses = response.BulkEntitiesResponse;    //entityResponses - list of EntityResponses instance

            return(records);
        }
Exemple #4
0
        private void InsertZohoLeads(List <ZohoLead> leads)
        {
            try
            {
                ZCRMRestClient.Initialize(config);

                ZohoOAuthClient client = ZohoOAuthClient.GetInstance();
                if (!IsTokenGenerated("*****@*****.**"))
                {
                    ZohoOAuthTokens tokens = client.GenerateAccessToken(grantToken);
                }

                List <ZCRMRecord> listRecord = new List <ZCRMRecord>();

                foreach (var lead in leads)
                {
                    ZCRMRecord record = ZCRMRecord.GetInstance("Leads", null); //To get ZCRMRecord instance

                    if (lead.Offers != null)
                    {
                        record = InsertZohoLeadOffer(lead);
                        listRecord.Add(record);
                    }

                    if (lead.HighBidAmount != null)
                    {
                        record = InsertZohoLeadBid(lead);
                        listRecord.Add(record);
                    }

                    if (lead.MemberMessage != null)
                    {
                        record = InsertZohoLeadMessage(lead);
                        listRecord.Add(record);
                    }
                }

                ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads");
                BulkAPIResponse <ZCRMRecord> responseIns = moduleIns.CreateRecords(listRecord); //To call the create record method

                if (responseIns.HttpStatusCode != ZCRMSDK.CRM.Library.Api.APIConstants.ResponseCode.OK)
                {
                    Console.WriteLine("Error");
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw ex;
            }
        }
Exemple #5
0
        public MainWindow()
        {
            Dictionary <string, string> config = new Dictionary <string, string>()
            {
                { "client_id", "1000.CA55W5WB17IEJHLXLMIPIL6T6ZC8QH" },
                { "client_secret", "c81a851b825ca20e89e1868a4a15f3581dc06fb38e" },
                { "redirect_uri", "https://www.google.com/" },
                { "access_type", "offline" },
                { "iamUrl", "https://accounts.zoho.com" },
                { "persistence_handler_class", "ZCRMSDK.OAuth.ClientApp.ZohoOAuthFilePersistence,ZCRMSDK" },
                { "oauth_tokens_file_path", "C:\\Users\\Admin\\source\\repos\\WpfApp1\\tokens.txt" },
                { "mysql_username", "root" },
                { "mysql_password", "" },
                { "mysql_database", "zohooauth" },
                { "mysql_server", "localhost" },
                { "mysql_port", "3306" },
                { "apiBaseUrl", "https://www.zohoapis.com" },
                { "photoUrl", "{photo_url}" },
                { "apiVersion", "v2" },
                { "logFilePath", "C:\\Users\\source\\repos\\WpfApp1\\logFile.txt" },
                { "timeout", "" },
                { "minLogLevel", "" },
                { "domainSuffix", "com" },
                { "currentUserEmail", "*****@*****.**" }
            };

            InitializeComponent();
            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient client      = ZohoOAuthClient.GetInstance();
            List <string>   fieldsLeads = new List <string> {
                "id", "First_Name", "Last_Name", "E_mail", "Print_Status"
            };
            ZCRMModule moduleIns    = ZCRMModule.GetInstance("Leads");
            string     modifiedTime = DateTime.Today.ToString("yyyy-MM-dd'T'HH:mm:ss");
            BulkAPIResponse <ZCRMRecord> response = moduleIns.GetRecords(2187808000000087509, "id", CommonUtil.SortOrder.asc, 1, 200, modifiedTime, fieldsLeads);
            dynamic records = JObject.Parse((response.ResponseJSON).ToString());
            var     data    = records.data;

            if (data != null)
            {
                List <Lead> leadsList = new List <Lead>();

                foreach (var record in data)
                {
                    leadsList.Add(new Lead {
                        isSelected = false, id = record.id, First_Name = record.First_Name, Last_Name = record.Last_Name, E_mail = record.E_mail, Print_Status = record.Print_Status
                    });
                }
                leadsGrid.ItemsSource = leadsList;
            }
        }
Exemple #6
0
        public ZCRMRecord GetSpecificRecord(string crmModuleName, long recordId)
        {
            try
            {
                ZCRMModule  moduleIns = ZCRMModule.GetInstance(crmModuleName); //module api name
                APIResponse response  = moduleIns.GetRecord(recordId);         //3372164000000190001 is record id
                ZCRMRecord  record    = (ZCRMRecord)response.Data;

                return(record);
            }
            catch (Exception exception)
            {
                return(null);
            }
        }
Exemple #7
0
        public List <ZCRMField> GetFields(string crmModuleName)
        {
            try
            {
                ZCRMModule moduleIns = ZCRMModule.GetInstance(crmModuleName);    //module api name
                BulkAPIResponse <ZCRMField> response = moduleIns.GetAllFields(); //3372164000000190001 is record id
                List <ZCRMField>            records  = response.BulkData;

                return(records);
            }
            catch (Exception exception)
            {
                return(null);
            }
        }
Exemple #8
0
 public List <ZCRMRecord> GetAllRecords(string crmModuleName)
 {
     try
     {
         ZCRMModule    moduleIns = ZCRMModule.GetInstance(crmModuleName); //module api name
         List <string> fields    = new List <string> {
             "Last_Name", "Company", "Email", "id"
         };                                                                    //field api name
         BulkAPIResponse <ZCRMRecord> response = moduleIns.GetRecords(fields); // get Records with cvId, sortByField, sortOrder, startIndex, endIndex and fieldApiNamelist.
         List <ZCRMRecord>            records  = response.BulkData;
         return(records);
     }
     catch (Exception exception)
     {
         return(null);
     }
 }
Exemple #9
0
        // POST api/issuer
        public List <ZCRMRecord> Post()
        {
            //tesst
            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            var dbContext = new MS_DEVEntities();
            var data      = dbContext.Database.SqlQuery <IssuerModel>("select BusinessName,FullName,Mobilenumber,UserName,ActualAmount,max(daysoverdue) as daysoverdue, sum(totaldisbursed) as totaldisbursed, convert(decimal(18,2),sum(isnull(overdueamount,0)))as overdueamount, convert(decimal(18,2),sum(isnull(outstandinglf,0)))as outstandinglf,convert(decimal(18,2),sum(isnull(outamountwithoutlf,0)))as outamountwithoutlf,convert(decimal(18,2),sum(isnull(outamountwithlf,0)))as outamountwithlf, max(lastrepaymentdate)as lastrepaymentdate,convert(decimal(18,2), sum(isnull(totalpaidamount,0)))as totalpaidamount,convert(decimal(18,2),sum(isnull(totalpaidprincipal,0)))as totalpaidprincipal,convert(decimal(18,2),sum(isnull(totalpaidinterest,0)))as totalpaidinterest,convert(decimal(18,2), sum(isnull(totalpaidlateinterest,0)))as totalpaidlateinterest,convert(decimal(18,2),sum(isnull(paidlatefees,0)))as paidlatefees from( select company.BusinessName, company.FullName,case when company.Mobilenumber = '94389427' and company.UserName = '******' then '97521852' else company.Mobilenumber end as Mobilenumber,case when company.UserName = '******' then '*****@*****.**' else company.UserName end as UserName,company.ActualAmount,max(DAYS_OVERDUE) as daysoverdue, sum(finalamount) as totaldisbursed, sum(isnull(overdueamount, 0)) as overdueamount, sum(isnull(outstandinglf, 0)) as outstandinglf,sum(isnull(outamountwithoutlf, 0)) as outamountwithoutlf,sum(isnull(outamountwithlf, 0)) as outamountwithlf, max(lastrepaymentdate) as lastrepaymentdate, sum(isnull(totalpaidamount, 0)) as totalpaidamount,sum(isnull(totalpaidprincipal, 0)) as totalpaidprincipal,sum(isnull(totalpaidinterest, 0)) as totalpaidinterest, sum(isnull(totalpaidlateinterest, 0)) as totalpaidlateinterest,sum(isnull(paidlatefees, 0)) as paidlatefees from(  select LoanRequestID, overduesincedate, lastrepaymentdate,case when LoanStatus = 8 then 0 else DAYS_OVERDUE end as days_overdue, case when loanstatus = 8 then 0 else overdueamount end as overdueamount,case when loanstatus = 8 then 0 else outamountwithoutlf end as outamountwithoutlf, case when LoanStatus = 8 then 0 else outamountwitlf end as outamountwithlf,case when LoanStatus = 8 then 0 else outstandinglf end as outstandinglf,case when LoanRequestID in (2036, 2001, 2037, 2019, 2004, 2059, 2020, 1994, 2053) then 0 else FinalAmount end as FinalAmount, paidlatefees,totalpaidamount,totalpaidprincipal,totalpaidinterest,totalpaidlateinterest from(  select z.*,y.lastrepaymentdate,x.DAYS_OVERDUE,x.overdueamount,w.numofoutstandingrepayment,w.numofoverduerepayment,w.numofpaidrepayment,w.totalnumofrepayment,v.outamountwithoutlf,v.outamountwitlf,v.outstandinglf,u.FinalAmount,s.paidlatefees,r.totalpaidamount,q.accepteddate,p.totalpaidprincipal,o.totalpaidinterest,n.totalpaidlateinterest,m.LoanStatus from(                   select loanrequestid, min(iif(paystatus= 2, duedate,null)) as overduesincedate from issuerrepayment group by LoanRequestID) as z left join( select LoanRequestID, max(date) as lastrepaymentdate from issuerrepayment right join issuerrepaymentpayment  on issuerrepayment.IssuerRepID = IssuerRepaymentPayment.IssuerRepID group by LoanRequestID) as y on z.LoanRequestID = y.LoanRequestID left join( select a1.*,b1.overdueamount from( select loanrequestid, isnull(DATEDIFF(day, MIN(IIF(PAYSTATUS<> 1,DUEDATE, NULL)),GETDATE()),0) AS DAYS_OVERDUE from issuerrepayment group by LoanRequestID ) as a1 left join( Select distinct LoanRequestID, Case when paystatus = 2 then SUM(Principal -isnull(PaidPrincipal, 0) - isnull(PaidInterest, 0) + Interest + isnull(lateinterest, 0)) over(partition by loanrequestID) else 0 end as overdueamount from IssuerRepayment where PayStatus = 2 ) as b1 on a1.LoanRequestID = b1.LoanRequestID) as x on z.LoanRequestID = x.LoanRequestID left join( select t.*,isnull(numpaid.numofpaidrepayment, 0) as numofpaidrepayment, isnull(numoverdue.numofoverduerepayment, 0) as numofoverduerepayment, isnull(numoutstanding.numofoutstandingrepayment, 0) as numofoutstandingrepayment from( select LoanRequestID, count(issuerrepid) as totalnumofrepayment  from IssuerRepayment group by LoanRequestID) as t left join( select LoanRequestID, count(issuerrepid) as numofpaidrepayment from IssuerRepayment where PayStatus = 1 group by LoanRequestID) as numpaid on t.LoanRequestID = numpaid.LoanRequestID left join( select LoanRequestID, count(issuerrepid) as numofoverduerepayment from IssuerRepayment where PayStatus = 2 group by LoanRequestID ) as numoverdue on t.LoanRequestID = numoverdue.LoanRequestID left join( select LoanRequestID, count(issuerrepid) as numofoutstandingrepayment from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as numoutstanding on t.LoanRequestID = numoutstanding.LoanRequestID) as w on z.LoanRequestID = w.LoanRequestID left join( select LoanRequestID, sum((isnull(latefees,0)-isnull(paidlatefees, 0))*(1 - isfeewaiver))as outstandinglf,sum(principal - isnull(paidprincipal, 0) + Interest - isnull(paidinterest, 0) + isnull(lateinterest, 0)) as outamountwithoutlf,sum(principal - isnull(paidprincipal, 0) + Interest - isnull(paidinterest, 0) + isnull(lateinterest, 0) + (isnull(latefees, 0) - isnull(paidlatefees, 0)) * (1 - isfeewaiver)) as outamountwitlf from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as v on z.LoanRequestID = v.LoanRequestID left join( select RequestId, FinalAmount from tbl_LoanRequests ) as u on z.LoanRequestID = u.RequestId left join( select loanrequestid, sum(isnull(paidprincipal,0)+isnull(paidinterest, 0) + isnull(paidlateinterest, 0)) as totalamountpaid from issuerrepayment group by loanrequestid) t on z.LoanRequestID = t.LoanRequestID left join( select loanrequestid, sum(isnull(paidlatefees,0)) as paidlatefees from issuerrepayment where IsFeeWaiver = 0 group by loanrequestid) as s on z.LoanRequestID = s.LoanRequestID left join( select case when a.LoanRequestID is not null then a.LoanRequestID else b.LoanRequestID end as loanrequestid, isnull(totalpaid, 0) + isnull(totalpaida, 0) as totalpaidamount from(  select LoanRequestID, sum(amount + isnull(PaidLateInterest, 0)) as totalpaid from IssuerRepayment where paystatus = 1 group by LoanRequestID) as a full join(select LoanRequestID, sum(isnull(paidprincipal,0)+isnull(paidinterest, 0) + isnull(paidlateinterest, 0)) as totalpaida from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as b on a.loanrequestid = b.loanrequestid ) as r on z.LoanRequestID = r.loanrequestid left join( select requestid, accepteddate from tbl_loanrequests) as q on z.loanrequestid = q.requestid left join( select case when a.LoanRequestID is not null then a.LoanRequestID else b.LoanRequestID end as loanrequestid, isnull(totalpaid, 0) + isnull(totalpaida, 0) as totalpaidprincipal from( select LoanRequestID, sum(Principal) as totalpaid from IssuerRepayment where paystatus = 1 group by LoanRequestID) as a full join(select LoanRequestID, sum(isnull(paidprincipal,0)) as totalpaida from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as b on a.loanrequestid = b.loanrequestid) as p on z.LoanRequestID = p.loanrequestid left join( select case when a.LoanRequestID is not null then a.LoanRequestID else b.LoanRequestID end as loanrequestid, isnull(totalpaid, 0) + isnull(totalpaida, 0) as totalpaidinterest from(  select LoanRequestID, sum(interest) as totalpaid from IssuerRepayment where paystatus = 1 group by LoanRequestID) as a full join(select LoanRequestID, sum(isnull(PaidInterest,0)) as totalpaida from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as b on a.loanrequestid = b.loanrequestid) as o on z.LoanRequestID = o.loanrequestid left join( select case when a.LoanRequestID is not null then a.LoanRequestID else b.LoanRequestID end as loanrequestid, isnull(totalpaid, 0) + isnull(totalpaida, 0) as totalpaidlateinterest from(  select LoanRequestID, sum(isnull(paidlateinterest, 0)) as totalpaid from IssuerRepayment where paystatus = 1 group by LoanRequestID) as a full join(select LoanRequestID, sum(isnull(PaidInterest,0)) as totalpaida from IssuerRepayment where PayStatus <> 1 group by LoanRequestID) as b on a.loanrequestid = b.loanrequestid) as n on z.LoanRequestID = n.loanrequestid left join( select RequestId, LoanStatus from tbl_loanRequests) as m on z.LoanRequestID = m.RequestId ) as notelevelmini  ) as notelevel left join( select accountdetails.BusinessName, tbl_loanrequests.RequestId, accountdetails.FullName, accountdetails.Mobilenumber, users.UserName, balance.ActualAmount from tbl_loanrequests left join(select BusinessName, NRIC_Number, USER_ID, FullName, Mobilenumber from tbl_AccountDetails) as accountdetails on accountdetails.user_ID = tbl_loanrequests.user_ID left join( select userid, username from tbl_Users) as users on tbl_LoanRequests.User_ID = users.UserID left join( select User_ID, ActualAmount from tbl_Balances) as balance on tbl_LoanRequests.User_ID = balance.User_ID) as company on notelevel.LoanRequestID = company.RequestId group by BusinessName, fullname, UserName, Mobilenumber,ActualAmount) as abc group by BusinessName,FullName,UserName,Mobilenumber,ActualAmount ").ToList();
            //foreach (var rc in data)
            //{
            ZCRMRecord record1 = new ZCRMRecord("accounts"); //module api name

            record1.SetFieldValue("CompanyName", "rc.CompanyName");
            record1.SetFieldValue("FullName", "rc.FullName");
            record1.SetFieldValue("UserName", "rc.UserName");
            record1.SetFieldValue("MobileNumber", "rc.MobileNumber");
            record1.SetFieldValue("IssuerAccountBalance", "rc.IssuerAccountBalance");
            record1.SetFieldValue("OverdueDate", "rc.OverdueDate");
            record1.SetFieldValue("TotalAmountDisbursed", "rc.TotalAmountDisbursed");
            record1.SetFieldValue("TotalAmountOverdue", "rc.TotalAmountOverdue");
            record1.SetFieldValue("OutstandingLateFee", "rc.OutstandingLateFee");
            record1.SetFieldValue("OutstandingAmountNoLateFee", "rc.OutstandingAmountNoLateFee");
            record1.SetFieldValue("OutstandingAmountWithLateFee", "rc.OutstandingAmountWithLateFee");
            record1.SetFieldValue("LastRepaymentDate", "rc.LastRepaymentDate");
            record1.SetFieldValue("TotalFeesPaid", "rc.TotalFeesPaid");
            record1.SetFieldValue("TotalPrincipalPaid", "rc.TotalPrincipalPaid");
            record1.SetFieldValue("TotalInterestPaid", "rc.TotalInterestPaid");
            record1.SetFieldValue("TotalLateInterestPaid", " rc.TotalLateInterestPaid");
            records.Add(record1);
            //ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
            //BulkAPIResponse<ZCRMRecord> response = moduleIns.CreateRecords(records);
            // }
            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                       //module api name
            BulkAPIResponse <ZCRMRecord> response        = moduleIns.CreateRecords(records); //records - list of ZCRMRecord instances filled with required data for upsert.
            List <ZCRMRecord>            upsertedRecords = response.BulkData;                //upsertedRecords - list of ZCRMRecord instance
            List <EntityResponse>        entityResponses = response.BulkEntitiesResponse;    //entityResponses - list of EntityResponses instance

            return(records);
        }
        private ZCRMModule GetZCRMModule(JObject moduleDetails)
        {
            try
            {
                ZCRMModule module = ZCRMModule.GetInstance((string)moduleDetails["api_name"]);
                if (moduleDetails.ContainsKey("global_search_supported") && moduleDetails["global_search_supported"].Type != JTokenType.Null)
                {
                    module.GlobalSearchSupported = (bool)moduleDetails["global_search_supported"];
                }
                if (moduleDetails.ContainsKey("kanban_view") && moduleDetails["kanban_view"].Type != JTokenType.Null)
                {
                    module.KanbanView = (bool)moduleDetails["kanban_view"];
                }
                module.Deletable = (bool)moduleDetails["deletable"];
                module.Creatable = (bool)moduleDetails["creatable"];
                if (moduleDetails.ContainsKey("filter_status") && moduleDetails["filter_status"].Type != JTokenType.Null)
                {
                    module.FilterStatus = (bool)moduleDetails["filter_status"];
                }
                if (moduleDetails.ContainsKey("inventory_template_supported") && moduleDetails["inventory_template_supported"].Type != JTokenType.Null)
                {
                    module.InventoryTemplateSupported = (bool)moduleDetails["inventory_template_supported"];
                }
                if (moduleDetails.ContainsKey("modified_time") && moduleDetails["modified_time"].Type != JTokenType.Null)
                {
                    module.ModifiedTime = CommonUtil.RemoveEscaping((string)JsonConvert.SerializeObject(moduleDetails["modified_time"]));
                }
                module.PluralLabel = (string)moduleDetails["plural_label"];
                if (moduleDetails.ContainsKey("presence_sub_menu") && moduleDetails["presence_sub_menu"].Type != JTokenType.Null)
                {
                    module.PresenceSubMenu = (bool)moduleDetails["presence_sub_menu"];
                }
                module.Id = Convert.ToInt64(moduleDetails["id"]);
                if (moduleDetails.ContainsKey("related_list_properties") && moduleDetails["related_list_properties"].Type != JTokenType.Null)
                {
                    module.RelatedListProperties = GetRelatedListProperties((JObject)moduleDetails["related_list_properties"]);
                }
                if (moduleDetails.ContainsKey("$properties") && moduleDetails["$properties"].Type != JTokenType.Null)
                {
                    List <string> properties = new List <string>();
                    foreach (string property in (JArray)moduleDetails["$properties"])
                    {
                        properties.Add(property);
                    }
                    module.Properties = properties;
                }
                if (moduleDetails.ContainsKey("per_page") && moduleDetails["per_page"].Type != JTokenType.Null)
                {
                    module.PerPage = (int)moduleDetails["per_page"];
                }
                if (moduleDetails.ContainsKey("visibility") && moduleDetails["visibility"].Type != JTokenType.Null)
                {
                    module.Visibility = (int)moduleDetails["visibility"];
                }
                module.Convertable = (bool)moduleDetails["convertable"];
                module.Editable    = (bool)moduleDetails["editable"];
                if (moduleDetails.ContainsKey("emailTemplate_support") && moduleDetails["emailTemplate_support"].Type != JTokenType.Null)
                {
                    module.EmailTemplateSupport = (bool)moduleDetails["emailTemplate_support"];
                }
                if (moduleDetails["profiles"].HasValues)
                {
                    JArray accessibleProfilesArray = (JArray)moduleDetails["profiles"];
                    foreach (JObject accessibleProfiles in accessibleProfilesArray)
                    {
                        ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles["id"]), (string)accessibleProfiles["name"]);
                        module.AddAccessibleProfile(profile);
                    }
                }
                if (moduleDetails.ContainsKey("filter_supported") && moduleDetails["filter_supported"].Type != JTokenType.Null)
                {
                    module.FilterSupported = (bool)moduleDetails["filter_supported"];
                }
                if (moduleDetails.ContainsKey("display_field") && moduleDetails["display_field"].Type != JTokenType.Null)
                {
                    module.DisplayField = (string)moduleDetails["display_field"];
                }
                if (moduleDetails.ContainsKey("search_layout_fields") && moduleDetails["search_layout_fields"].Type != JTokenType.Null)
                {
                    List <string> layout_Fields = new List <string>();
                    foreach (string layout_Field in (JArray)moduleDetails["search_layout_fields"])
                    {
                        layout_Fields.Add(layout_Field);
                    }
                    module.SearchLayoutFields = layout_Fields;
                }
                if (moduleDetails.ContainsKey("kanban_view_supported") && moduleDetails["kanban_view_supported"].Type != JTokenType.Null)
                {
                    module.KanbanViewSupported = (bool)moduleDetails["kanban_view_supported"];
                }
                module.WebLink        = (string)moduleDetails["web_link"];
                module.SequenceNumber = (int)moduleDetails["sequence_number"];
                module.SingularLabel  = (string)moduleDetails["singular_label"];
                module.Viewable       = (bool)moduleDetails["viewable"];
                module.ApiSupported   = (bool)(moduleDetails["api_supported"]);
                if (moduleDetails.ContainsKey("quick_create") && moduleDetails["quick_create"].Type != JTokenType.Null)
                {
                    module.QuickCreate = (bool)(moduleDetails["quick_create"]);
                }
                if (moduleDetails["modified_by"].HasValues)
                {
                    JObject  modifiedByObject = (JObject)moduleDetails["modified_by"];
                    ZCRMUser modifiedUser     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]);
                    module.ModifiedBy = modifiedUser;
                }
                module.CustomModule = (bool)(moduleDetails["generated_type"].ToString().Equals("custom"));
                if (moduleDetails.ContainsKey("feeds_required") && moduleDetails["feeds_required"].Type != JTokenType.Null)
                {
                    module.FeedsRequired = (bool)(moduleDetails["feeds_required"]);
                }
                if (moduleDetails.ContainsKey("scoring_supported") && moduleDetails["scoring_supported"].Type != JTokenType.Null)
                {
                    module.ScoringSupported = (bool)(moduleDetails["scoring_supported"]);
                }
                if (moduleDetails.ContainsKey("webform_supported") && moduleDetails["webform_supported"].Type != JTokenType.Null)
                {
                    module.WebformSupported = (bool)(moduleDetails["webform_supported"]);
                }
                if (moduleDetails.ContainsKey("arguments") && moduleDetails["arguments"].Type != JTokenType.Null)
                {
                    if (moduleDetails["arguments"].HasValues)
                    {
                        List <ZCRMWebTabArguments> argumentsList = new List <ZCRMWebTabArguments>();
                        JArray argumentsJArr = (JArray)moduleDetails["arguments"];
                        foreach (JObject argumentsJObj in argumentsJArr)
                        {
                            ZCRMWebTabArguments argumentsIns = ZCRMWebTabArguments.GetInstance();
                            if (argumentsJObj.ContainsKey("name") && argumentsJObj["name"].Type != JTokenType.Null)
                            {
                                argumentsIns.Name = (string)argumentsJObj["name"];
                            }
                            if (argumentsJObj.ContainsKey("value") && argumentsJObj["value"].Type != JTokenType.Null)
                            {
                                argumentsIns.Value = (string)argumentsJObj["value"];
                            }
                            argumentsList.Add(argumentsIns);
                        }
                        module.WebTabArguments = argumentsList;
                    }
                }
                module.SystemName = (string)moduleDetails["module_name"];
                if (moduleDetails.ContainsKey("business_card_field_limit") && moduleDetails["business_card_field_limit"].Type != JTokenType.Null)
                {
                    module.BusinessCardFieldLimit = (int)moduleDetails["business_card_field_limit"];
                }
                if (moduleDetails.ContainsKey("custom_view") && moduleDetails["custom_view"].Type != JTokenType.Null)
                {
                    module.CustomView = GetZCRMCustomView((string)moduleDetails["api_name"], (JObject)moduleDetails["custom_view"]);
                }
                if (moduleDetails.ContainsKey("parent_module") && moduleDetails["parent_module"].Type != JTokenType.Null)
                {
                    if (moduleDetails["parent_module"].HasValues)
                    {
                        JObject    parent_module   = (JObject)moduleDetails["parent_module"];
                        ZCRMModule parentModuleIns = ZCRMModule.GetInstance((string)parent_module["api_name"]);
                        parentModuleIns.Id  = Convert.ToInt64(parent_module["id"]);
                        module.ParentModule = parentModuleIns;
                    }
                }
                if (moduleDetails.ContainsKey("territory") && moduleDetails["territory"].Type != JTokenType.Null)
                {
                    JObject       territoryJobj = (JObject)moduleDetails["territory"];
                    ZCRMTerritory territoryIns  = ZCRMTerritory.GetInstance(Convert.ToInt64(territoryJobj["id"]));
                    territoryIns.Name         = (string)territoryJobj["name"];
                    territoryIns.Subordinates = (bool)territoryJobj["subordinates"];
                    module.Territory          = territoryIns;
                }
                if (moduleDetails.ContainsKey("related_lists") && moduleDetails["related_lists"].Type != JTokenType.Null)
                {
                    List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>();
                    JArray relatedListsArray = (JArray)moduleDetails["related_lists"];
                    foreach (JObject relatedListDetails in relatedListsArray)
                    {
                        ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, (string)relatedListDetails["api_name"]);
                        SetRelatedListProperties(relatedList, relatedListDetails);
                        relatedLists.Add(relatedList);
                    }
                    module.RelatedLists = relatedLists;
                }

                if (moduleDetails.ContainsKey("fields") && moduleDetails["fields"].Type != JTokenType.Null)
                {
                    JArray fieldArray = (JArray)moduleDetails["fields"];
                    module.Fields = ModuleAPIHandler.GetInstance(ZCRMModule.GetInstance((string)moduleDetails["api_name"])).GetFields(fieldArray);
                }
                if (moduleDetails.ContainsKey("business_card_fields") && moduleDetails.Type != JTokenType.Null)
                {
                    List <string> bcFields      = new List <string>();
                    JArray        bcFieldsArray = (JArray)moduleDetails["business_card_fields"];
                    foreach (JObject bcField in bcFieldsArray)
                    {
                        bcFields.Add(bcField.ToString());
                    }
                    module.BussinessCardFields = bcFields;
                }
                if (moduleDetails.ContainsKey("layouts"))
                {
                    module.Layouts = ModuleAPIHandler.GetInstance(module).GetAllLayouts(moduleDetails);
                }
                return(module);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemple #11
0
 /// <summary>
 /// To get ZohoCRM modules' instance by passing module API name.
 /// </summary>
 /// <returns>ZCRMModule class instance.</returns>
 /// <param name="moduleAPIName">modules' API name (String)</param>
 public ZCRMModule GetModuleInstance(string moduleAPIName)
 {
     return(ZCRMModule.GetInstance(moduleAPIName));
 }
Exemple #12
0
        public void UpdateInvestor(InvestorModel investor)
        {
            var id = dbzoho.tbl_CheckID.FirstOrDefault(p => p.EmailMS == investor.UserName);

            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            ZCRMRecord        record1      = new ZCRMRecord("accounts"); //module api name

            record1.EntityId = id.IDZoho;
            record1.SetFieldValue("id", id.IDZoho);
            record1.SetFieldValue("Account_Name", investor.UserName);
            record1.SetFieldValue("Email", investor.UserName);
            record1.SetFieldValue("Username", investor.UserName);
            record1.SetFieldValue("Industry", "1");
            record1.SetFieldValue("Status", "1");
            record1.SetFieldValue("Phone", investor.MobileNumber);
            record1.SetFieldValue("Fax", investor.MobileNumber);
            record1.SetFieldValue("Employees", 1);
            record1.SetFieldValue("Age", investor.Age);
            record1.SetFieldValue("Gender", investor.Gender);
            record1.SetFieldValue("NRIC_Number", investor.NRIC_Number);
            record1.SetFieldValue("Passport_Number", investor.PassportNumber);
            record1.SetFieldValue("Date_Of_Birth", investor.DateOfBirth.Value);
            record1.SetFieldValue("Sign_Up_Date", investor.DateCreated.Value.Date.ToString());
            record1.SetFieldValue("Total_Invested", investor.TotalInvestedAmount);
            record1.SetFieldValue("Admin_Verification", investor.AdminVerification);
            record1.SetFieldValue("Number_Of_Delinquent_Off_Note", investor.numofdelinquent);
            record1.SetFieldValue("Number_Of_Fully_Paid_Note", investor.NumberOfFullyPaidNotes);
            record1.SetFieldValue("Number_of_Close_Off_Note", investor.NumOfCloseOff);
            record1.SetFieldValue("Qualified_Date", investor.QualifiedDate.Value.Date.ToString());
            if (investor.LastLogin == null)
            {
                investor.LastLogin = investor.DateCreated;
            }
            record1.SetFieldValue("Number_Of_Deliquent_Note", investor.numofdelinquent);
            record1.SetFieldValue("Last_Login", investor.LastLogin.Value.Date.ToString());
            record1.SetFieldValue("Sum_of_Number_Invested_Note", investor.NumberOfInvested);
            record1.SetFieldValue("Current_in_Funding_Amount", investor.CurrentInFunding);
            record1.SetFieldValue("Sum_of_Ledge_Amount", investor.ActualAmount);
            record1.SetFieldValue("Total_Amount_Received", investor.TotalAmountReceived);
            record1.SetFieldValue("Total_Delinquent_Amount", investor.outstandingPI);
            record1.SetFieldValue("Outstanding_L", investor.outstanding_I);
            record1.SetFieldValue("Outstanding_P", investor.outstanding_P);
            record1.SetFieldValue("Principal_Received", investor.PaidP);
            record1.SetFieldValue("Interest_Received", investor.PaidI);
            records.Add(record1);


            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                   //module api name
            BulkAPIResponse <ZCRMRecord> responseIns = moduleIns.UpdateRecords(records); //To call the Update record method

            Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode);         //To get Update record http response code
            foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
            {
                Console.WriteLine("Status:" + response.Status);        //To get Update record response status
                Console.WriteLine("Message:" + response.Message);      //To get Update record response message
                Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
                ZCRMRecord record11 = (ZCRMRecord)response.Data;
                Console.WriteLine(record11.EntityId);                  //To get inserted record id
                Console.WriteLine(record11.CreatedTime);
                Console.WriteLine(record11.ModifiedTime);
                ZCRMUser CreatedBy = record11.CreatedBy;
                if (CreatedBy != null)
                {
                    Console.WriteLine(CreatedBy.Id);
                    Console.WriteLine(CreatedBy.FullName);
                }
                ZCRMUser ModifiedBy = record1.ModifiedBy;
                if (ModifiedBy != null)
                {
                    Console.WriteLine(ModifiedBy.Id);
                    Console.WriteLine(ModifiedBy.FullName);
                }
            }
        }
Exemple #13
0
        //public BulkAPIResponse<ZCRMRecord> InsertInvestor(InvestorModel investor)
        //{

        //    ZCRMRestClient.Initialize(config);
        //    ZohoOAuthClient client = ZohoOAuthClient.GetInstance();
        //    string refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
        //    string userMailId = "*****@*****.**";
        //    ZohoOAuthTokens tokens = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
        //    List<ZCRMRecord> records = new List<ZCRMRecord>();
        //    ZCRMRecord record1 = new ZCRMRecord("accounts"); //module api name

        //    record1.SetFieldValue("Account_Name", investor.UserName);
        //    record1.SetFieldValue("Email", investor.UserName);
        //    record1.SetFieldValue("Username", investor.UserName);
        //    record1.SetFieldValue("Industry", "1");
        //    record1.SetFieldValue("Status", "1");
        //    record1.SetFieldValue("Phone", investor.MobileNumber);
        //    record1.SetFieldValue("Fax", investor.MobileNumber);
        //    record1.SetFieldValue("Employees", 1);
        //    record1.SetFieldValue("Age", investor.Age);
        //    record1.SetFieldValue("Gender", investor.Gender);
        //    record1.SetFieldValue("NRIC_Number", investor.NRIC_Number);
        //    record1.SetFieldValue("Passport_Number", investor.PassportNumber);
        //    record1.SetFieldValue("Date_Of_Birth", investor.DateOfBirth.Value);
        //    record1.SetFieldValue("Sign_Up_Date", investor.DateCreated.Value.Date.ToString());
        //    record1.SetFieldValue("Total_Invested", investor.TotalInvestedAmount);
        //    record1.SetFieldValue("Admin_Verification", investor.AdminVerification);
        //    record1.SetFieldValue("Number_Of_Delinquent_Off_Note", investor.numofdelinquent);
        //    record1.SetFieldValue("Number_Of_Fully_Paid_Note", investor.NumberOfFullyPaidNotes);
        //    record1.SetFieldValue("Number_of_Close_Off_Note", investor.NumOfCloseOff);
        //    record1.SetFieldValue("Qualified_Date", investor.QualifiedDate.Value.Date.ToString());
        //    if (investor.LastLogin == null)
        //    {
        //        investor.LastLogin = investor.DateCreated;
        //    }
        //    record1.SetFieldValue("Last_Login", investor.LastLogin.Value.Date.ToString());
        //    record1.SetFieldValue("Number_Of_Deliquent_Note", investor.numofdelinquent);
        //    record1.SetFieldValue("Sum_of_Number_Invested_Note", investor.NumberOfInvested);
        //    record1.SetFieldValue("Current_in_Funding_Amount", investor.CurrentInFunding);
        //    record1.SetFieldValue("Sum_of_Ledge_Amount", investor.ActualAmount);
        //    record1.SetFieldValue("Total_Amount_Received", investor.TotalAmountReceived);
        //    record1.SetFieldValue("Total_Delinquent_Amount", investor.outstandingPI);
        //    record1.SetFieldValue("Outstanding_L", investor.outstanding_I);
        //    record1.SetFieldValue("Outstanding_P", investor.outstanding_P);
        //    record1.SetFieldValue("Principal_Received", investor.PaidP);
        //    record1.SetFieldValue("Interest_Received", investor.PaidI);
        //    record1.CreatedTime = DateTime.UtcNow.Ticks.ToString();
        //    records.Add(record1);


        //    ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts"); //module api name
        //    BulkAPIResponse<ZCRMRecord> response = moduleIns.CreateRecords(records); //records - list of ZCRMRecord instances filled with required data for upsert.
        //    List<ZCRMRecord> insertedRecords = response.BulkData; //upsertedRecords - list of ZCRMRecord instance
        //    foreach (var entityID in response.BulkData)
        //    {
        //        var newID = new tbl_CheckID
        //        {
        //            IDZoho = entityID.EntityId,
        //            EmailMS = investor.UserName
        //        };
        //        dbzoho.tbl_CheckID.Add(newID);
        //        dbzoho.SaveChanges();
        //    }

        //    List<EntityResponse> entityResponses = response.BulkEntitiesResponse; //entityResponses - list of EntityResponses instance
        //    return response;
        //}
        public void UpdateIssuer(IssuerModel issuer)
        {
            var id = dbzoho.tbl_CheckID.FirstOrDefault(p => p.EmailMS == issuer.UserName);

            ZCRMRestClient.Initialize(config);
            ZohoOAuthClient   client       = ZohoOAuthClient.GetInstance();
            string            refreshToken = "1000.354c162c19b5da4fc4053bc4e38dd27f.1e548f961cc913acbacd82fbad0a3387";
            string            userMailId   = "*****@*****.**";
            ZohoOAuthTokens   tokens       = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            ZCRMRecord        record1      = new ZCRMRecord("accounts"); //module api name

            record1.EntityId = id.IDZoho;
            record1.SetFieldValue("id", id.IDZoho);
            record1.SetFieldValue("Account_Name", issuer.UserName);
            record1.SetFieldValue("Full_Name", issuer.FullName);
            record1.SetFieldValue("Username", issuer.UserName);
            record1.SetFieldValue("Industry", "1");
            record1.SetFieldValue("Company_Name", issuer.BusinessName.ToString());
            record1.SetFieldValue("Phone", issuer.MobileNumber);
            record1.SetFieldValue("Fax", issuer.MobileNumber);
            record1.SetFieldValue("Employees", 1);
            record1.SetFieldValue("Total_Amount_Disbursed", issuer.totaldisbursed);
            record1.SetFieldValue("Last_Repayment_Date", issuer.LastRepaymentDate.Value.ToString());
            record1.SetFieldValue("Days_Overdue", issuer.daysoverdue);
            record1.SetFieldValue("Issuer_Account_Balance", issuer.ActualAmount);
            record1.SetFieldValue("Outstanding_Amount_with_Late_Fee", issuer.outamountwithlf);
            record1.SetFieldValue("Outstanding_Amount_no_Late_Fee", issuer.outamountwithoutlf);
            record1.SetFieldValue("Outstanding_Late_Fee", issuer.outstandinglf);
            record1.SetFieldValue("Total_Amount_Overdue", issuer.overdueamount);
            record1.SetFieldValue("Total_Principle_Paid", issuer.totalpaidprincipal);
            record1.SetFieldValue("Total_Interest_Paid", issuer.totalpaidinterest);
            record1.SetFieldValue("Total_Late_Fee_Paid", issuer.paidlatefees);
            record1.SetFieldValue("Total_Late_Interest_Paid", issuer.totalpaidlateinterest);
            record1.SetFieldValue("Total_Paid_Amount", issuer.TotalPaidAmount);
            records.Add(record1);


            ZCRMModule moduleIns = ZCRMModule.GetInstance("accounts");                   //module api name
            BulkAPIResponse <ZCRMRecord> responseIns = moduleIns.UpdateRecords(records); //To call the Update record method

            Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode);         //To get Update record http response code
            foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
            {
                Console.WriteLine("Status:" + response.Status);        //To get Update record response status
                Console.WriteLine("Message:" + response.Message);      //To get Update record response message
                Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
                ZCRMRecord record11 = (ZCRMRecord)response.Data;
                Console.WriteLine(record11.EntityId);                  //To get inserted record id
                Console.WriteLine(record11.CreatedTime);
                Console.WriteLine(record11.ModifiedTime);
                ZCRMUser CreatedBy = record11.CreatedBy;
                if (CreatedBy != null)
                {
                    Console.WriteLine(CreatedBy.Id);
                    Console.WriteLine(CreatedBy.FullName);
                }
                ZCRMUser ModifiedBy = record1.ModifiedBy;
                if (ModifiedBy != null)
                {
                    Console.WriteLine(ModifiedBy.Id);
                    Console.WriteLine(ModifiedBy.FullName);
                }
            }
        }
 private ZCRMModule GetZCRMModule(JObject moduleDetails)
 {
     try
     {
         ZCRMModule module = ZCRMModule.GetInstance((string)moduleDetails["api_name"]);
         module.Id            = Convert.ToInt64(moduleDetails["id"]);
         module.SystemName    = (string)moduleDetails["module_name"];
         module.SingularLabel = (string)moduleDetails["singular_label"];
         module.PluralLabel   = (string)moduleDetails["plural_label"];
         module.Creatable     = (bool)moduleDetails["creatable"];
         module.Viewable      = (bool)moduleDetails["viewable"];
         module.Editable      = (bool)moduleDetails["editable"];
         module.Convertable   = (bool)moduleDetails["convertable"];
         module.Deletable     = (bool)moduleDetails["deletable"];
         module.CustomModule  = (bool)(moduleDetails["generated_type"].ToString().Equals("custom"));
         module.ApiSupported  = (bool)(moduleDetails["api_supported"]);
         JArray accessibleProfilesArray = (JArray)moduleDetails["profiles"];
         foreach (JObject accessibleProfiles in accessibleProfilesArray)
         {
             ZCRMProfile profile = ZCRMProfile.GetInstance(Convert.ToInt64(accessibleProfiles["id"]), (string)accessibleProfiles["name"]);
             module.AddAccessibleProfile(profile);
         }
         if (moduleDetails["modified_by"].HasValues)
         {
             JObject  modifiedByObject = (JObject)moduleDetails["modified_by"];
             ZCRMUser modifiedUser     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedByObject["id"]), (string)modifiedByObject["name"]);
             module.ModifiedBy   = modifiedUser;
             module.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(moduleDetails["modified_time"]));
         }
         if (moduleDetails.ContainsKey("related_lists") && moduleDetails["related_lists"].Type != JTokenType.Null)
         {
             List <ZCRMModuleRelation> relatedLists = new List <ZCRMModuleRelation>();
             JArray relatedListsArray = (JArray)moduleDetails["related_lists"];
             foreach (JObject relatedListDetails in relatedListsArray)
             {
                 ZCRMModuleRelation relatedList = ZCRMModuleRelation.GetInstance(module.ApiName, (string)relatedListDetails["api_name"]);
                 SetRelatedListProperties(relatedList, relatedListDetails);
                 relatedLists.Add(relatedList);
             }
             module.RelatedLists = relatedLists;
         }
         if (moduleDetails.ContainsKey("business_card_fields") && moduleDetails.Type != JTokenType.Null)
         {
             List <string> bcFields      = new List <string>();
             JArray        bcFieldsArray = (JArray)moduleDetails["business_card_fields"];
             foreach (JObject bcField in bcFieldsArray)
             {
                 bcFields.Add(bcField.ToString());
             }
             module.BussinessCardFields = bcFields;
         }
         if (moduleDetails.ContainsKey("layouts"))
         {
             module.Layouts = ModuleAPIHandler.GetInstance(module).GetAllLayouts(moduleDetails);
         }
         return(module);
     }
     catch (Exception e) when(!(e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
Exemple #15
0
        private ZCRMRecord InsertZohoLeadOffer(ZohoLead lead)
        {
            try
            {
                ZCRMRecord record = ZCRMRecord.GetInstance("Leads", null); //To get ZCRMRecord instance

                if (lead.Offers.Count > 0)
                {
                    Offer leadOffer = lead.Offers.First();
                    record.SetFieldValue("Offer_Amount1", leadOffer.OfferAmount);
                    record.SetFieldValue("Offer_Expiration", new DateTime(leadOffer.OfferExpirationDate.Year, leadOffer.OfferExpirationDate.Month, leadOffer.OfferExpirationDate.Day, leadOffer.OfferExpirationDate.Hour, leadOffer.OfferExpirationDate.Minute, leadOffer.OfferExpirationDate.Second));
                }

                //lead.StockNumber = "2168";
                if (!String.IsNullOrEmpty(lead.StockNumber))
                {
                    record.SetFieldValue("Stock_Number", lead.StockNumber);

                    ZCRMModule module = ZCRMModule.GetInstance("Contacts");
                    BulkAPIResponse <ZCRMRecord> response = module.SearchByCriteria("(Cust_ID:equals:" + lead.StockNumber + ")");
                    List <ZCRMRecord>            contacts = response.BulkData;

                    if (contacts != null)
                    {
                        if (contacts.Count > 0)
                        {
                            JObject customerId = new JObject()
                            {
                                { "id", contacts.First().EntityId }
                            };
                            record.SetFieldValue("Stock_Nbr", customerId);
                        }
                    }
                }

                if (lead.PageViews != null)
                {
                    record.SetFieldValue("Page_Views", lead.PageViews);
                }

                if (lead.Watchers != null)
                {
                    record.SetFieldValue("Current_Watchers", lead.Watchers.ToString());
                }

                if (!String.IsNullOrEmpty(lead.VehicleYear))
                {
                    record.SetFieldValue("Year_of_Unit", lead.VehicleYear);
                }

                if (!String.IsNullOrEmpty(lead.PhoneNumber))
                {
                    record.SetFieldValue("Phone_Number", lead.PhoneNumber);
                }
                if (!String.IsNullOrEmpty(lead.VehicleMake))
                {
                    record.SetFieldValue("Year_Make_Model", lead.VehicleMake + " " + lead.VehicleModel);
                    record.SetFieldValue("Year_Make_Model1", lead.VehicleMake + " " + lead.VehicleModel);
                }

                record.SetFieldValue("Item_Number", lead.EbayItemId);

                if (!String.IsNullOrEmpty(lead.City))
                {
                    record.SetFieldValue("Bidders_City", lead.City);
                }
                if (!String.IsNullOrEmpty(lead.State))
                {
                    record.SetFieldValue("Bidders_State", lead.State);
                }
                record.SetFieldValue("Last_Name", lead.LastName);
                record.SetFieldValue("Name1", lead.FullName);
                record.SetFieldValue("Email_provided", lead.Email);

                record.SetFieldValue("Ebay_User_ID", lead.UserId);

                JObject layout = new JObject()
                {
                    { "id", 4212012000003357243 }
                };
                //string layout = "{\"name\", \"Ebay Offer\",\"id\", \4212012000003357243\"}";

                record.SetFieldValue("Layout", layout);

                return(record);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw ex;
            }
        }
Exemple #16
0
        private ZCRMRecord InsertZohoLeadMessage(ZohoLead lead)
        {
            try
            {
                ZCRMRecord record = ZCRMRecord.GetInstance("Leads", null); //To get ZCRMRecord instance

                //lead.StockNumber = "2168";
                if (!String.IsNullOrEmpty(lead.StockNumber))
                {
                    record.SetFieldValue("Stock_Number", lead.StockNumber);

                    ZCRMModule module = ZCRMModule.GetInstance("Contacts");
                    BulkAPIResponse <ZCRMRecord> response = module.SearchByCriteria("(Cust_ID:equals:" + lead.StockNumber + ")");
                    List <ZCRMRecord>            contacts = response.BulkData;

                    if (contacts != null)
                    {
                        if (contacts.Count > 0)
                        {
                            JObject customerId = new JObject()
                            {
                                { "id", contacts.First().EntityId }
                            };
                            record.SetFieldValue("Stock_Nbr", customerId);
                        }
                    }
                }

                if (lead.PageViews != null)
                {
                    record.SetFieldValue("Page_Views", lead.PageViews);
                }

                if (!String.IsNullOrEmpty(lead.StockNumber))
                {
                    record.SetFieldValue("Registered_Watchers", lead.Watchers);
                }

                if (!String.IsNullOrEmpty(lead.MemberMessage))
                {
                    record.SetFieldValue("Description", lead.MemberMessage);
                }

                if (!String.IsNullOrEmpty(lead.VehicleYear))
                {
                    record.SetFieldValue("Year_of_Unit", lead.VehicleYear);
                }

                if (!String.IsNullOrEmpty(lead.PhoneNumber))
                {
                    record.SetFieldValue("Phone_Number", lead.PhoneNumber);
                }

                if (!String.IsNullOrEmpty(lead.VehicleMake))
                {
                    record.SetFieldValue("Year_Make_Model", lead.VehicleMake + " " + lead.VehicleModel);
                    record.SetFieldValue("Year_Make_Model1", lead.VehicleMake + " " + lead.VehicleModel);
                }

                if (!String.IsNullOrEmpty(lead.EbayItemId))
                {
                    record.SetFieldValue("Item_Number", lead.EbayItemId);
                }

                if (!String.IsNullOrEmpty(lead.City))
                {
                    record.SetFieldValue("Bidders_City", lead.City);
                }

                if (!String.IsNullOrEmpty(lead.State))
                {
                    record.SetFieldValue("Bidders_State", lead.State);
                }

                record.SetFieldValue("Last_Name", lead.LastName);
                record.SetFieldValue("First_Name", lead.FirstName);
                record.SetFieldValue("Name1", lead.FullName);
                record.SetFieldValue("Name2", lead.FullName);
                record.SetFieldValue("Email", lead.Email);
                record.SetFieldValue("Email_provided", lead.Email);
                record.SetFieldValue("Ebay_User_ID", lead.UserId);

                JObject layout = new JObject()
                {
                    { "id", 4212012000003357573 }
                };

                record.SetFieldValue("Layout", layout);

                return(record);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw ex;
            }
        }