private int CheckForRegistrationAvailalibilityForContact(string registrationId, string clientId, string logId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            GetRelationshipsRequest request = new GetRelationshipsRequest
            {
                session         = suitesessionId,
                module_id       = registrationId,
                module_name     = "reg_Registration",
                link_field_name = "contacts_reg_registration_1",
                related_fields  = new List <string>()
                {
                    "id"
                },
                related_module_query = $"contacts_reg_registration_1contacts_ida='{clientId}'"
            };

            try
            {
                var registration_List = suiteWrapper.GetRelationship <GetRelationshipsResponse>(request).GetAwaiter().GetResult();
                return(registration_List.SugarEntryList.Count());
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetSuiteAddress", "Error : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "GetSuiteAddress", Entity_c = "Customer"
                }, logId);
            }
            return(-1);
        }
        public HttpResponseMessage GetModulesDetails()
        {
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }
            try
            {
                var req = new SuiteAPI.ReadEntryListRequest();
                req.SessionId  = sessionId;
                req.ModuleName = "Contacts";
                req.MethodName = "get_module_fields";
                var list = SuiteWrapper.GetModuleList <CMSModels.ModuleDetails>(req).GetAwaiter().GetResult();
                return(Request.CreateResponse(HttpStatusCode.OK, list));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
        public JToken GetListSuiteRegistration(string auctionCalenderId, string clientId, string logId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var request = new SuiteReadEntryListRequest();

            request.SessionId  = suitesessionId;
            request.ModuleName = "reg_Registration";
            request.Query      = "reg_Registration_cstm.ac1_auction_calendar_id_c='" + auctionCalenderId + "'";
            //request.Query = $"reg_Registration_cstm.ac1_auction_calendar_id_c='{auctionCalenderId}' and id in ( SELECT contacts_reg_registration_1reg_registration_idb  FROM contacts_reg_registration_1_c  where contacts_reg_registration_1contacts_ida = '{clientId}') ";
            request.SelectFields = new List <string> {
                "id",
            };

            var registration_list = suiteWrapper.GetList(request).GetAwaiter().GetResult();

            foreach (var registratonRecord in registration_list.EntityList)
            {
                if (CheckForRegistrationAvailalibilityForContact(registratonRecord.SelectToken("id").ToString(), clientId, logId) > 0)
                {
                    return(registratonRecord);
                }
            }
            return(null);
        }
        public void UpdateContactRegistration(string reg_id, string contact_id, string logId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            SetRelationShipRequest relationshipRequest = new SetRelationShipRequest();

            relationshipRequest.session         = suitesessionId;
            relationshipRequest.module_name     = "reg_Registration";
            relationshipRequest.module_id       = reg_id;
            relationshipRequest.link_field_name = "contacts_reg_registration_1contacts_ida";
            relationshipRequest.related_ids     = new List <string>()
            {
                contact_id
            };

            var relationshipResponse = suiteWrapper.SetRelationship(relationshipRequest).GetAwaiter().GetResult();

            if (relationshipResponse == null)
            {
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Failed to update Client id in Suite Registration Id: " + reg_id, Name = "InsertSuiteRegistration", Entity_c = "Registration"
                }, logId);
                SuiteWrapper.WriteTraceLog("InsertSuiteRegistration", "Failed to update Client id in Suite Registration  Id: " + reg_id);
            }
        }
        public HttpResponseMessage UploadLotNumber(UploadLotNumber[] uploadLotNumberRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'UploadLotNumber' with request :" + JsonConvert.SerializeObject(uploadLotNumberRequest));
            var    sessionId     = "0";
            string outputMessage = string.Empty;

            foreach (var data in uploadLotNumberRequest)
            {
                if (!SuiteWrapper.ValidateRequest(data, out outputMessage))
                {
                    //Trace Log
                    SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(data) + " is : " + outputMessage);
                    return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
                }
            }
            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            PushResponseforMultipleEntries <UploadLotNumber> pushResponse = new PushResponseforMultipleEntries <UploadLotNumber>();
            var pushResponseResult = pushResponse.BuildResponse(sessionId, uploadLotNumberRequest, "Itm1_Item");

            SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pushResponseResult));
            return(Request.CreateResponse(HttpStatusCode.OK, pushResponseResult));
        }
        private int GetSuiteAddressCount(string ContactId, string LogId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            GetRelationshipsRequest request = new GetRelationshipsRequest
            {
                session         = suitesessionId,
                module_id       = ContactId,
                module_name     = "Contacts",
                link_field_name = "contacts_add1_addresses_1",
                related_fields  = new List <string>()
                {
                    "id"
                }
            };

            try
            {
                var suiteAddress = suiteWrapper.GetRelationship <GetRelationshipsResponse>(request).GetAwaiter().GetResult();
                return(suiteAddress.SugarEntryList.Count());
            }

            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetSuiteAddress", "Error : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "GetSuiteAddress", Entity_c = "Customer"
                }, LogId);
            }
            return(-1);
        }
        private string InsertSuiteRegistration(CreateRegistrationRequest registerRequest, string logId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var request = new InsertRequest();

            request.SessionId  = suitesessionId;
            request.ModuleName = "reg_Registration";
            request.Entity     = registerRequest;
            var resp = suiteWrapper.Insert(request).GetAwaiter().GetResult();

            if (resp != null)
            {
                UpdateContactRegistration(resp.Id, registerRequest.Contact_id, logId);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Inserted Suite Registration successfully Id: " + resp.Id, Name = "InsertSuiteRegistration", Entity_c = "Registration"
                }, logId);
                SuiteWrapper.WriteTraceLog("InsertSuiteRegistration", "Inserted Suite Registration successfully Id: " + resp.Id);
                return(resp.Id);
            }
            return(null);
        }
Ejemplo n.º 8
0
        public List <EntryListArray> GetSuiteContactIDByEmail(string email, string logId)
        {
            var wrapper = new SuiteWrapper();

            suitesessionId = wrapper.Login().GetAwaiter().GetResult();

            var request = new SuiteReadEntryListRequest();

            request.SessionId  = suitesessionId;
            request.ModuleName = "Contacts";
            request.Query      = " contacts" +
                                 ".id in (SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON " +
                                 "(ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address = '" + email + "')";
            request.SelectFields = new List <string> {
                "Am_customer_id",
                "email"
            };
            try
            {
                var suiteConstactList = wrapper.GetList(request).GetAwaiter().GetResult();
                return(suiteConstactList.EntryList);
            }

            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetRegistration", "Error : " + ex.Message);
                InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "GetSuiteConstactIDByEmail", Entity_c = "Customer"
                }, logId);
            }
            return(null);
        }
Ejemplo n.º 9
0
        public CreateTraceLogResponse InsertSuiteAmIntegrationLogDetail(CreateTraceLogRequest result_page, string logId)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var tracelogrequest = new CreateTraceLogRequest();

            tracelogrequest.Name                    = result_page.Name;
            tracelogrequest.Description             = result_page.Description;
            tracelogrequest.Entity_c                = result_page.Entity_c;
            tracelogrequest.Sync_date_c             = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            tracelogrequest.Integration_summary_ida = logId;
            if (!string.IsNullOrEmpty(result_page.Email_c))
            {
                tracelogrequest.Email_c = result_page.Email_c;
            }

            var request_Integration_Detail = new InsertRequest
            {
                SessionId  = suitesessionId,
                ModuleName = "pndl_AM_Integration_Detail",
                Entity     = tracelogrequest
            };

            suiteWrapper.Insert(request_Integration_Detail).GetAwaiter().GetResult();

            return(null);
        }
        private void InsertSuiteAddress(AMCustomer.AMAddress addrDetails, SuiteContact suiteContact, string logId)
        {
            try
            {
                var suiteWrapper = new SuiteWrapper();
                suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

                var addressrequest = new CreateAddressRequest();

                addressrequest.Name            = suiteContact.Name;
                addressrequest.Country         = addrDetails.Country_code;
                addressrequest.Address1        = addrDetails.Street_address;
                addressrequest.City            = addrDetails.Locality;
                addressrequest.Client_number_c = suiteContact.Client_number_c;
                addressrequest.State           = addrDetails.Region;

                addressrequest.Zip = addrDetails.Postal_code;

                if (addrDetails.Type == "home" || addrDetails.Type == null)
                {
                    addressrequest.Shipping_address = true;
                }

                if (addrDetails.Type == "billing")
                {
                    addressrequest.Billing_address = true;
                }


                addressrequest.Contacts_add1_addresses_1contacts_ida = suiteContact.Id;

                var request = new InsertRequest();
                request.SessionId  = suitesessionId;
                request.ModuleName = "add1_Addresses";
                request.Entity     = addressrequest;
                var resp = suiteWrapper.Insert(request).GetAwaiter().GetResult();

                if (resp == null)
                {
                    SuiteWrapper.WriteTraceLog("InsertSuiteAddress", "Error : In updating Address for client Number");
                }
            }
            catch (Exception ex)
            {
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "InsertSuiteAddress", Entity_c = "Registration"
                }, logId);
                SuiteWrapper.WriteTraceLog("InsertSuiteAddress", "Error : " + ex.Message);
            }
        }
        private string UpdateCustomerRecord(JToken amCustomers_Result, string suiteConstactId, string logId)
        {
            try
            {
                if (amCustomers_Result != null && suiteConstactId != null)
                {
                    var suiteWrapper = new SuiteWrapper();
                    suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

                    var contactrequest = new CreateContactRequest
                    {
                        Email           = Convert.ToString(amCustomers_Result.SelectToken("preferred_email")),
                        Phone           = Convert.ToString(amCustomers_Result.SelectToken("phone_number")),
                        FirstName       = Convert.ToString(amCustomers_Result.SelectToken("given_name")),
                        LastName        = Convert.ToString(amCustomers_Result.SelectToken("family_name")),
                        Salutation      = Convert.ToString(amCustomers_Result.SelectToken("title")),
                        Fax             = Convert.ToString(amCustomers_Result.SelectToken("fax_number")),
                        Comments        = Convert.ToString(amCustomers_Result.SelectToken("notes")),
                        ContactType     = "Individual",
                        CompanyName     = Convert.ToString(amCustomers_Result.SelectToken("company_name")),
                        AMCustomerId    = Convert.ToString(amCustomers_Result.SelectToken("row_id")),
                        Approvalestatus = "Pending_Approval",
                        Id = suiteConstactId
                    };

                    var request = new InsertRequest
                    {
                        SessionId  = suitesessionId,
                        ModuleName = "Contacts",
                        Entity     = contactrequest
                    };
                    var resp = suiteWrapper.Update(request).GetAwaiter().GetResult();
                    common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                    {
                        Description = "Updated Customer RecordID :" + resp.Id, Name = "InsertSuiteContact", Entity_c = "Customer"
                    }, logId);
                    SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Updated Customer RecordID :" + resp.Id);
                    return(resp.Id);
                }
            }
            catch (Exception ex)
            {
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "InsertSuiteContact", Entity_c = "Customer"
                }, logId);
                SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Error : " + ex.Message);
            }
            return("");
        }
        public HttpResponseMessage MoveItem(MoveItem moveItemRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'MoveItem' with request :" + JsonConvert.SerializeObject(moveItemRequest));
            var    sessionId     = "0";
            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(moveItemRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(moveItemRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }
            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            PushResponseforSingleEntry pushResponseforSingleEntry = new PushResponseforSingleEntry();

            try
            {
                var req = new AddUpdateSingleEntryRequest();
                req.SessionId  = sessionId;
                req.ModuleName = "Itm1_Item";
                req.Entity     = moveItemRequest;
                var response = SuiteWrapper.AddUpdateSingleEntry(req).GetAwaiter().GetResult();
                pushResponseforSingleEntry.Id     = response.Id;
                pushResponseforSingleEntry.Status = "Success";

                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pushResponseforSingleEntry));
                return(Request.CreateResponse(HttpStatusCode.OK, pushResponseforSingleEntry));
            }
            catch (Exception ex)
            {
                pushResponseforSingleEntry.Id     = null;
                pushResponseforSingleEntry.Status = ex.Message.ToString();

                SuiteWrapper.WriteTraceLog("Exception while pushing data is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, pushResponseforSingleEntry));
            }
        }
        public HttpResponseMessage PushSymbols(PushSymbols[] symbolsRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'PushSymbols' with request :" + JsonConvert.SerializeObject(symbolsRequest));
            var sessionId = "0";
            // Validating
            string outputMessage = string.Empty;

            foreach (var data in symbolsRequest)
            {
                if (!SuiteWrapper.ValidateRequest(data, out outputMessage))
                {
                    //Trace Log
                    SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(data) + " is : " + outputMessage);
                    return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
                }
            }
            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }
            try
            {
                var request = new AddUpdateMultipleEntriesRequest();
                request.SessionId  = sessionId;
                request.ModuleName = "Sym1_Symbols";
                request.Entity     = symbolsRequest;
                var response = SuiteWrapper.AddUpdateMultipleEntries(request).GetAwaiter().GetResult();

                PushResponseforMultipleEntries <PushSymbols> pushResponse = new PushResponseforMultipleEntries <PushSymbols>();
                var pushResponseResult = pushResponse.BuildResponse(sessionId, symbolsRequest, "Sym1_Symbols");

                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pushResponseResult));

                return(Request.CreateResponse(HttpStatusCode.OK, pushResponseResult));
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while Adding/updating the data is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
        //Path: /api/Contact/PullContacts
        public HttpResponseMessage PullContacts()
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called PullClientData");
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            try
            {
                List <string> vs = new List <string>();
                vs.Add("id");

                var req = new SuiteAPI.ReadEntryListRequest();
                req.SessionId             = sessionId;
                req.MethodName            = "get_entry_list";
                req.ModuleName            = "Contacts";
                req.LinkNameToFieldsArray = new Dictionary <string, object>()
                {
                    { "name", "contacts_add1_addresses_1" },
                    { "value", vs }
                };
                PropertyInfo[] props = typeof(PullContact).GetProperties();
                req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                var list         = SuiteWrapper.GetList <PullContact>(req).GetAwaiter().GetResult();
                var pullResponse = PullResponseWithoutPagination <PullContact> .pullResponse(list);


                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));
                return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while pulling data is : " + ex.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
Ejemplo n.º 15
0
        // Get NetSuite Customer internalID
        public SuiteContact GetSuiteConstactID(string auctionCustmoerID, string logId)
        {
            var suiteContact   = new SuiteContact();
            var amwrapper      = new AMWrapper();
            var suiteWrapper   = new SuiteWrapper();
            var contactrequest = new CreateContactRequest();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var request = new SuiteReadEntryListRequest();

            request.SessionId    = suitesessionId;
            request.ModuleName   = "Contacts";
            request.Query        = " am_customer_id_c = '" + auctionCustmoerID + "'";
            request.SelectFields = new List <string> {
                "id",
                "am_customer_id_c",
                "name",
                "client_number_c"
            };
            try
            {
                var suiteConstactlist = suiteWrapper.GetList(request).GetAwaiter().GetResult();

                foreach (var record in suiteConstactlist.EntryList)
                {
                    suiteContact.Id              = record.Entity.SelectToken("id").ToString();
                    suiteContact.Name            = record.Entity.SelectToken("name").ToString();
                    suiteContact.Client_number_c = record.Entity.SelectToken("client_number_c").ToString();
                    return(suiteContact);
                }
            }

            catch (Exception ex)
            {
                InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "CheckForRegistration", Entity_c = "Customer"
                }, logId);
                SuiteWrapper.WriteTraceLog("CheckForRegistration", "Error Message : " + ex.Message);
            }
            return(null);
        }
        public GetListofSuiteContactResponse GetListSuiteContact(GetListofSuiteContactRequest GetSuiteContactRequest)
        {
            var suiteWrapper = new SuiteWrapper();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var request = new SuiteReadEntryListRequest();

            request.SessionId    = suitesessionId;
            request.ModuleName   = "Contacts";
            request.SelectFields = new List <string> {
                "first_name",
                "last_name",
                "phone_work",
                "title",
                "phone_fax",
                "description",
            };

            var contacts_List = suiteWrapper.GetList(request).GetAwaiter().GetResult();

            for (var i = 0; i <= contacts_List.EntityList.Count(); i++)
            {
                var values = new Dictionary <string, string>
                {
                    { "method", "POST" },
                    { "input_type", "JSON" },
                    { "response_type", "JSON" },
                    { "email_address", "*****@*****.**" },
                    { "given_name", "ABC" },
                    { "family_name", "Xyz" },
                    { "password", "1234567890" },
                    { "first_name", contacts_List.EntryList[i].Entity.SelectToken("first_name").ToString() },
                    { "last_name", contacts_List.EntryList[i].Entity.SelectToken("last_name").ToString() },
                    { "phone_work", contacts_List.EntryList[i].Entity.SelectToken("phone_work").ToString() },
                    { "title", contacts_List.EntryList[i].Entity.SelectToken("title").ToString() },
                    { "phone_fax", contacts_List.EntryList[i].Entity.SelectToken("phone_fax").ToString() },
                    { "description", contacts_List.EntryList[i].Entity.SelectToken("description").ToString() }
                };
            }

            return(null);
        }
        public EntryListArray GetListSuiteAuctionCalender(string id, string logId)
        {
            var amWrapper      = new AMWrapper();
            var suiteWrapper   = new SuiteWrapper();
            var contactrequest = new CreateContactRequest();

            suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

            var request = new SuiteReadEntryListRequest();

            request.SessionId    = suitesessionId;
            request.ModuleName   = "AC1_Auction_Calendar";
            request.Query        = "AC1_Auction_Calendar.id='" + id + "'";
            request.SelectFields = new List <string> {
                "name",
            };

            var auction_List = suiteWrapper.GetList(request).GetAwaiter().GetResult();

            if (auction_List.EntityList == null)
            {
                return(null);
            }

            var auction_List_Cnt = auction_List.EntityList.Count();

            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Total Auction Calender in Suite: " + auction_List_Cnt, Name = "GetListSuiteAuctionCalender", Entity_c = "Registration"
            }, logId);
            if (auction_List.EntityList.Count() == 0)
            {
                return(null);
            }
            for (var i = 0; i <= auction_List_Cnt; i++)
            {
                return(auction_List.EntryList[i]);
            }
            return(null);
        }
        public PushListofSuiteAuctionResponse PushListofAMAuction(string auctionId, string logId)
        {
            SuiteWrapper.WriteTraceLog("PushAMAuction", "---------------- AUCTION SYNC START ------------------------- ");
            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Push Auction to AM sync started", Name = "PushAuction", Entity_c = "Auction"
            }, logId);

            var amWrapper    = new AMWrapper();
            var suiteWrapper = new SuiteWrapper();


            var ret = new PushListofSuiteAuctionResponse();

            ret.List = new List <AMCustomer.AMAuction>();
            try
            {
                suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

                var requestAuction = new SuiteReadEntryListRequest();
                requestAuction.SessionId    = suitesessionId;
                requestAuction.ModuleName   = "AC1_Auction_Calendar";
                requestAuction.Query        = $"ac1_auction_calendar_cstm.auction_number_c in ('{string.Join("','", auctionId.Split(','))}')";
                requestAuction.SelectFields = new List <string> {
                    "id",
                    "name",
                    "auction_number_c",
                    "auction_type_c",
                    "currency_type_c",
                    "start_date_c",
                    "invoice_description_c",
                    "viewing_c",
                    "city_description_c",
                    "city_c",
                };

                var auction_List = suiteWrapper.GetList(requestAuction).GetAwaiter().GetResult();

                if (auction_List.Count > 0)
                {
                    foreach (var item in auction_List.EntityList.Children())
                    {
                        var itemProperties = item.Children <JProperty>();

                        var values = new Dictionary <string, string>
                        {
                            { "method", "POST" },
                            { "input_type", "JSON" },
                            { "response_type", "JSON" },
                            { "integration_id", itemProperties.FirstOrDefault(xx => xx.Name == "id").Value.ToString() },
                        };

                        if (!string.IsNullOrEmpty(itemProperties.FirstOrDefault(xx => xx.Name == "name").Value.ToString()))
                        {
                            values.Add("title", itemProperties.FirstOrDefault(xx => xx.Name == "name").Value.ToString());
                        }

                        values.Add("auction_code", itemProperties.FirstOrDefault(xx => xx.Name == "auction_number_c").Value.ToString());

                        var auction_type_c = GetAuctionType(itemProperties.FirstOrDefault(xx => xx.Name == "auction_type_c").Value.ToString());
                        values.Add("auction_type", auction_type_c);


                        var currency_type_c = GetCurrencyCode(itemProperties.FirstOrDefault(xx => xx.Name == "currency_type_c").Value.ToString());
                        values.Add("currency_code", currency_type_c);

                        values.Add("location_name", itemProperties.FirstOrDefault(xx => xx.Name == "city_c").Value.ToString());

                        string start_date_c = Convert.ToDateTime(itemProperties.FirstOrDefault(xx => xx.Name == "start_date_c").Value.ToString()).ToString("yyyy-MM-dd'T'HH:mm'Z'");

                        values.Add("time_start", start_date_c);

                        values.Add("description", itemProperties.FirstOrDefault(xx => xx.Name == "invoice_description_c").Value.ToString());

                        values.Add("viewing_information", itemProperties.FirstOrDefault(xx => xx.Name == "viewing_c").Value.ToString());

                        values.Add("location_description", itemProperties.FirstOrDefault(xx => xx.Name == "city_description_c").Value.ToString());

                        var result_Auction = amWrapper.PostDataToAM(values, $"{amWrapper.apiUrl}/v1/auction/").GetAwaiter().GetResult();


                        var    responseData = JObject.Parse(result_Auction).SelectToken("response");
                        string AMId;
                        if (responseData != null)
                        {
                            AMId = responseData.SelectToken("row_id").ToString();
                            SuiteWrapper.WriteTraceLog("PushAMAuction", "Auction Inserted to AM successfully for Id :" + AMId);
                            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                            {
                                Description = "Auction Inserted to AM successfully for Id :" + itemProperties.FirstOrDefault(xx => xx.Name == "id").Value.ToString(), Name = "PushAMAuction", Entity_c = "Auction"
                            }, logId);
                            ret.StatusCode = ClsConstant.SuccessCode;
                            ret.Message    = ClsConstant.SuccessMessage;
                        }
                        else
                        {
                            var message = JObject.Parse(result_Auction).SelectToken("error");
                            AMId = "";
                            SuiteWrapper.WriteTraceLog("PushAMAuction", "Error Message : " + message);
                            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                            {
                                Description = "Error Message : " + message, Name = "PushAMAuction", Entity_c = "Auction"
                            }, logId);

                            ret.StatusCode = ClsConstant.ServerErrorCode;
                            ret.Message    = ClsConstant.ServerErrorMsg;
                        }

                        AMCustomer.AMAuction result = new AMCustomer.AMAuction();
                        result.SuiteId = itemProperties.FirstOrDefault(xx => xx.Name == "id").Value.ToString();
                        result.Row_id  = AMId;
                        ret.List.Add(result);
                    }
                }
                else
                {
                    common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                    {
                        Description = "No any Auction exist for period", Name = "PushAMAuction", Entity_c = "Auction"
                    }, logId);
                    SuiteWrapper.WriteTraceLog("PushAMAuction", "No any Auction exist for period");
                }
            }
            catch (Exception ex)
            {
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error Message : " + ex.Message, Name = "PushAMAuction", Entity_c = "Auction"
                }, logId);
                ret.StatusCode = ClsConstant.ServerErrorCode;
                ret.Message    = ClsConstant.ServerErrorMsg;

                return(ret);
            }
            SuiteWrapper.WriteTraceLog("PushAMAuction", "---------------- AUCTION SYNC END ------------------------- ");
            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Push Auction to AM sync ended", Name = "PushAMAuction", Entity_c = "Auction"
            }, logId);
            return(ret);
        }
        public HttpResponseMessage PullMasterData(string methodName, string lastSyncDate = null, int?nextOffSet = null, bool deleted = false)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'PullMasterData' with request : MethodName-" + methodName + " and nextOffSet=" + nextOffSet);
            var sessionId = "0";

            try
            {
                sessionId = SuiteWrapper.Login().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while generating session id is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message.ToString()));
            }

            var query = string.Empty;
            var req   = new SuiteAPI.ReadEntryListRequest();

            req.SessionId  = sessionId;
            req.MethodName = "get_entry_list";
            req.MaxResults = SuiteWrapper.maxPullResults;
            req.Deleted    = deleted;
            if (nextOffSet != null && nextOffSet > 0)
            {
                req.Offset = nextOffSet;
            }
            int v = (req.Deleted) ? 1 : 0;

            try
            {
                if (methodName == "Artists")
                {
                    req.ModuleName = "A1_Artists";
                    PropertyInfo[] props = typeof(PullArtist).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "A1_Artists.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and A1_Artists.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullArtist>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullArtist> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Auctions")
                {
                    req.ModuleName = "AC1_Auction_Calendar";
                    PropertyInfo[] props = typeof(PullAuctionCalendar).GetProperties();
                    query = "AC1_Auction_Calendar.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and AC1_Auction_Calendar.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullAuctionCalendar>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullAuctionCalendar> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Symbols")
                {
                    req.ModuleName = "Sym1_Symbols";
                    PropertyInfo[] props = typeof(PullSymbols).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "Sym1_Symbols.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and Sym1_Symbols.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullSymbols>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullSymbols> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Locations")
                {
                    req.ModuleName = "loc_Location";
                    PropertyInfo[] props = typeof(PullLocation).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "loc_Location.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and loc_Location.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullLocation>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullLocation> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else if (methodName == "Categories")
                {
                    req.ModuleName = "Cat1_Categories";
                    PropertyInfo[] props = typeof(PullCategories).GetProperties();
                    req.SelectFields = SuiteAPI.SuiteWrapper.GetFieldList(props);
                    query            = "Cat1_Categories.deleted=" + Convert.ToInt32((req.Deleted) ? 1 : 0) + " ";
                    if (!string.IsNullOrEmpty(lastSyncDate))
                    {
                        req.Query = query + "and Cat1_Categories.date_modified >='" + lastSyncDate + "'";
                    }
                    else
                    {
                        req.Query = query;
                    }
                    var list         = SuiteWrapper.GetList <PullCategories>(req).GetAwaiter().GetResult();
                    var pullResponse = PullResponse <PullCategories> .pullResponse(list, methodName, deleted, lastSyncDate);

                    SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(pullResponse));

                    return(Request.CreateResponse(HttpStatusCode.OK, pullResponse));
                }
                else
                {
                    SuiteWrapper.WriteTraceLog("Invalid Pull request method name : " + methodName);
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Method name '" + methodName + "' not found."));
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while pulling the data is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
        private string InsertSuiteContact(JToken AMCustomers_Result, string logId)
        {
            try
            {
                // Based on Email-id search Customer Record and update record
                var custEmail    = Convert.ToString(AMCustomers_Result.SelectToken("preferred_email"));
                var suiteContact = common.GetSuiteContactIDByEmail(custEmail, logId);
                var internalID   = string.Empty;


                if (suiteContact.Count() > 0)
                {
                    if (suiteContact.Count() == 1)
                    {
                        foreach (EntryListArray contact in suiteContact)
                        {
                            internalID = contact.Id;
                            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                            {
                                Description = "Only one record exist for email id :'" + custEmail + "' in Suite", Name = "InsertSuiteContact", Entity_c = "Customer"
                            }, logId);
                            SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Only one record exist for email id :'" + custEmail + "' in Suite");
                        }
                    }
                    else
                    {
                        if (custEmail != "*****@*****.**")
                        {
                            foreach (var k in suiteContact)
                            {
                                internalID = k.Id;
                                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                                {
                                    Email_c = custEmail, Description = "Multiple records exist for email id :'" + custEmail + "' in Suite: ", Name = "InsertSuiteContact", Entity_c = "Customer"
                                }, logId);
                                SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Multiple records exist for email id :'" + custEmail + "' in Suite: ");
                            }
                        }
                    }
                }
                else
                {
                    // Create NetSuite Customer Record
                    var suiteWrapper = new SuiteWrapper();
                    suitesessionId = suiteWrapper.Login().GetAwaiter().GetResult();

                    var contactrequest = new CreateContactRequest
                    {
                        Email           = Convert.ToString(AMCustomers_Result.SelectToken("preferred_email")),
                        Phone           = Convert.ToString(AMCustomers_Result.SelectToken("phone_number")),
                        FirstName       = Convert.ToString(AMCustomers_Result.SelectToken("given_name")),
                        LastName        = Convert.ToString(AMCustomers_Result.SelectToken("family_name")),
                        Salutation      = Convert.ToString(AMCustomers_Result.SelectToken("title")),
                        Fax             = Convert.ToString(AMCustomers_Result.SelectToken("fax_number")),
                        Comments        = Convert.ToString(AMCustomers_Result.SelectToken("notes")),
                        ContactType     = "Individual",
                        CompanyName     = Convert.ToString(AMCustomers_Result.SelectToken("company_name")),
                        AMCustomerId    = Convert.ToString(AMCustomers_Result.SelectToken("row_id")),
                        Approvalestatus = "Pending_Approval"
                    };

                    var request = new InsertRequest
                    {
                        SessionId  = suitesessionId,
                        ModuleName = "Contacts",
                        Entity     = contactrequest
                    };
                    var resp = suiteWrapper.Insert(request).GetAwaiter().GetResult();

                    common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                    {
                        Description = "Customer Inserted to Suite successfully for Id :" + resp.Id, Name = "InsertSuiteContact", Entity_c = "Customer"
                    }, logId);
                    SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Customer Inserted to Suite successfully for Id :" + resp.Id);

                    return(resp.Id);
                }
            }
            catch (Exception ex)
            {
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "InsertSuiteContact", Entity_c = "Customer"
                }, logId);
                SuiteWrapper.WriteTraceLog("InsertSuiteContact", "Error : " + ex.Message);
            }

            return("");
        }