예제 #1
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);
        }
        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 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));
        }
        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);
            }
        }
        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);
        }
        //Path: /api/Contact/ViewContact
        public HttpResponseMessage ViewContact(int contact_id)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'GetDropdownMasterData'");
            List <ViewContactData_Result> data = new List <ViewContactData_Result>();

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    var UpdEntity = context.contacts.AsNoTracking().FirstOrDefault(m => m.contact_id == contact_id);
                    if (UpdEntity == null)
                    {
                        SuiteWrapper.WriteTraceLog("Contact doesn't exist.");
                        return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Contact doesn't exist."));;
                    }

                    context.Configuration.ProxyCreationEnabled = false;
                    data = context.ViewContactData(contact_id).ToList();
                }

                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(data));
                return(Request.CreateResponse(HttpStatusCode.OK, data[0]));
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while Pulling the contact is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
        // Add Registration details to Customer subTab
        private string UpdateCustomerRecordRegistration(string auctionInternalId, SuiteContact suiteContact, string paddle, string startDate, string auctionName, string auctionType, string auctionTimeZone, string auctionViewingInfo, string auctionCurrencyCode, string auctionCity, AMCustomer.AMCustomer amCustomer, string logId)
        {
            try
            {
                if (auctionInternalId != "" && suiteContact.Id != "")
                {
                    var suiteCustomerAddressRecord = GetSuiteAddressCount(suiteContact.Id, logId);
                    //create address subrecord
                    if (amCustomer.Addresses.Count() > 0 && suiteCustomerAddressRecord == 0)
                    {
                        foreach (var amAddress in amCustomer.Addresses)
                        {
                            InsertSuiteAddress(amAddress, suiteContact, logId);
                        }
                    }
                }

                if (CheckForAuctionAvailability(auctionInternalId, logId))
                {
                    var recordID = CheckForRegistration(auctionInternalId, suiteContact, paddle, auctionName, logId);

                    return(recordID);
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("UpdateCustomerRecordRegistration", "Error Message : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "UpdateCustomerRecordRegistration", Entity_c = "Registration"
                }, logId);
            }
            return("");
        }
        public GetListofAMRegistrationResponse GetListofAMRegistration(string logId)
        {
            SuiteWrapper.WriteTraceLog("GetRegistration", "---------------- REGISTRATION SYNC START ------------------------- ");
            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Registration sync started", Name = "GetRegistration", Entity_c = "Registration"
            }, logId);

            var amWrapper = new AMWrapper();
            var ret       = new GetListofAMRegistrationResponse();

            try
            {
                var req = new ReadEntryListRequest();
                req.AccessToken = amWrapper.apiAccessToken;
                req.ModuleName  = "auction";
                var AMRegistration_List = amWrapper.GetAMList <AMCustomer.AMAuction>(req, $"{amWrapper.apiUrl}/v1/auction/upcoming").GetAwaiter().GetResult();

                var result_page = JObject.Parse(AMRegistration_List).SelectToken("result_page");

                var listOfUpcomingAuction = ReadAllAMAuctionUpcoming(result_page);

                ProcessSuiteRegistration(listOfUpcomingAuction, logId);

                var query_info    = JObject.Parse(AMRegistration_List).SelectToken("query_info");
                var next_page_url = string.Empty;

                foreach (var next_page in query_info.SelectTokens("next_page"))
                {
                    next_page_url = next_page.ToString();
                    while (!string.IsNullOrEmpty(next_page_url))
                    {
                        var jstr_Next        = amWrapper.GetAMList <AMCustomer.AMAuction>(req, next_page_url).GetAwaiter().GetResult();
                        var result_page_Next = JObject.Parse(jstr_Next).SelectToken("result_page");
                        listOfUpcomingAuction = ReadAllAMAuctionUpcoming(result_page_Next);
                        ProcessSuiteRegistration(listOfUpcomingAuction, logId);

                        var query_info_Next = JObject.Parse(jstr_Next).SelectToken("query_info");
                        foreach (var next_page1 in query_info_Next.SelectTokens("next_page"))
                        {
                            next_page_url = string.Empty;
                            next_page_url = next_page1.ToString();
                        }
                    }
                }

                ret.StatusCode = AMAPI.ClsConstant.SuccessCode;
                ret.Message    = AMAPI.ClsConstant.SuccessMessage;

                return(ret);
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetListofAMRegistration", "Error Message : " + ex.Message);
                ret.StatusCode = AMAPI.ClsConstant.ServerErrorCode;
                ret.Message    = AMAPI.ClsConstant.ServerErrorMsg;

                return(ret);
            }
        }
        //Path: /api/Contact/CreateContact
        public HttpResponseMessage CreateContact(ContactModel ContactModelRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'MoveItem' with request :" + JsonConvert.SerializeObject(ContactModelRequest));
            PushContactResponse pushContactResponse = new PushContactResponse();

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    contact contactObject = new contact();
                    contactObject.salutation                = ContactModelRequest.salutation;
                    contactObject.first_name                = ContactModelRequest.first_name;
                    contactObject.last_name                 = ContactModelRequest.last_name;
                    contactObject.company_name              = ContactModelRequest.company_name;
                    contactObject.contact_type              = ContactModelRequest.contact_type;
                    contactObject.client_number             = ContactModelRequest.client_number;
                    contactObject.interest_id               = ContactModelRequest.interest_id;
                    contactObject.category_id               = ContactModelRequest.category_id;
                    contactObject.customer_category_id      = ContactModelRequest.customer_category_id;
                    contactObject.level_id                  = ContactModelRequest.level_id;
                    contactObject.catalogue_id              = ContactModelRequest.catalogue_id;
                    contactObject.marital_status_id         = ContactModelRequest.marital_status_id;
                    contactObject.marriage_anniversary_date = ContactModelRequest.marriage_anniversary_date;
                    contactObject.am_customer_id            = ContactModelRequest.am_customer_id;
                    contactObject.approval_status_id        = ContactModelRequest.approval_status_id;
                    contactObject.authorized_to_bid_id      = ContactModelRequest.authorized_to_bid_id;
                    contactObject.email              = ContactModelRequest.email;
                    contactObject.phone              = ContactModelRequest.phone;
                    contactObject.fax                = ContactModelRequest.fax;
                    contactObject.mobile             = ContactModelRequest.mobile;
                    contactObject.other_phone        = ContactModelRequest.other_phone;
                    contactObject.clients_vat_tin_no = ContactModelRequest.clients_vat_tin_no;
                    contactObject.aadhar_number      = ContactModelRequest.aadhar_number;
                    contactObject.pan_no             = ContactModelRequest.pan_no;
                    contactObject.date_created       = DateTime.Now;
                    contactObject.date_modified      = DateTime.Now;
                    contactObject.createdby_id       = ContactModelRequest.createdby_id;
                    contactObject.modifiedby_id      = ContactModelRequest.createdby_id;
                    context.contacts.Add(contactObject);

                    context.SaveChanges();

                    pushContactResponse.contactid = contactObject.contact_id;
                    pushContactResponse.status    = "Success";

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

                SuiteWrapper.WriteTraceLog("Exception while pushing data is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(pushContactResponse)));
            }
        }
        private string GetAuctionIntegrationId(string aucId)
        {
            var amWrapper             = new AMWrapper();
            var ret                   = new GetListofAMAuctionResponse();
            var getListofAMAuctionReq = new GetListofAMAuctionRequest();

            ret.ReferenceID = getListofAMAuctionReq.ReferenceID;
            var aucIntId = string.Empty;

            try
            {
                var req = new ReadEntryListRequest();
                req.AccessToken = req.AccessToken;
                req.ModuleName  = "auction";
                var auction_Details = amWrapper.GetAMList <AMCustomer.AMAuction>(req, $"{amWrapper.apiUrl}/v1/auction/" + aucId + "/").GetAwaiter().GetResult();
                var result_page     = JObject.Parse(auction_Details).SelectToken("response");

                foreach (var result in result_page.SelectTokens("integration_id"))
                {
                    aucIntId = result.ToString();
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetAuctionIntegrationId", "Error Message : " + ex.Message);
            }
            return(aucIntId);
        }
        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);
        }
        // Get Auction registrations customer ID
        private List <AMCustomer.AMRegistration> GetAuctionRegistrationArray(string AuctionID, string LogId)
        {
            var amAuctionSummary = new List <AMCustomer.AMRegistration>();

            var amWrapper             = new AMWrapper();
            var ret                   = new GetListofAMAuctionResponse();
            var GetListofAMAuctionReq = new GetListofAMAuctionRequest();

            ret.ReferenceID = GetListofAMAuctionReq.ReferenceID;

            try
            {
                var req = new ReadEntryListRequest();
                req.AccessToken = req.AccessToken;
                req.ModuleName  = "auction";
                var list        = amWrapper.GetAMList <AMCustomer.AMRegistration>(req, $"{amWrapper.apiUrl}/v2/admin/auction/" + AuctionID + "/registrations?fieldset=customer-addresses").GetAwaiter().GetResult();
                var result_page = JObject.Parse(list).SelectToken("result_page");

                foreach (var result in result_page)
                {
                    amAuctionSummary.Add(GetAuctionSummary(result));
                }

                var query_info    = JObject.Parse(list).SelectToken("query_info");
                var next_page_url = string.Empty;

                foreach (var next_page in query_info.SelectTokens("next_page"))
                {
                    next_page_url = next_page.ToString();
                    while (!string.IsNullOrEmpty(next_page_url))
                    {
                        var jstr_Next        = amWrapper.GetAMList <AMCustomer.AMAuction>(req, next_page_url).GetAwaiter().GetResult();
                        var result_page_Next = JObject.Parse(jstr_Next).SelectToken("result_page");

                        foreach (var result in result_page)
                        {
                            amAuctionSummary.Add(GetAuctionSummary(result));
                        }

                        var query_info_Next = JObject.Parse(jstr_Next).SelectToken("query_info");
                        foreach (var next_page1 in query_info_Next.SelectTokens("next_page"))
                        {
                            next_page_url = string.Empty;
                            next_page_url = next_page1.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetSuiteAddress", "Error : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error Message : " + ex.Message, Name = "GetSuiteAddress", Entity_c = "Registration"
                }, LogId);
            }

            return(amAuctionSummary);
        }
        //Path: /api/User/UpdateUser
        public HttpResponseMessage UpdateUser(UpdateUserModel updateUserModelRequest)
        {
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'UpdateUser' with request :" + JsonConvert.SerializeObject(updateUserModelRequest));

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(updateUserModelRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(updateUserModelRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    var UpdEntity = context.users.AsNoTracking().FirstOrDefault(m => m.id == updateUserModelRequest.id);
                    if (UpdEntity == null)
                    {
                        SuiteWrapper.WriteTraceLog("User doesn't exist.");
                        return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "User doesn't exist."));;
                    }

                    UpdEntity.user_name = updateUserModelRequest.user_name;
                    if (!string.IsNullOrEmpty(updateUserModelRequest.user_hash))
                    {
                        UpdEntity.user_hash = SuiteWrapper.CreateMD5(updateUserModelRequest.user_hash);
                    }

                    UpdEntity.first_name      = updateUserModelRequest.first_name;
                    UpdEntity.last_name       = updateUserModelRequest.last_name;
                    UpdEntity.phone_home      = updateUserModelRequest.phone_home;
                    UpdEntity.phone_mobile    = updateUserModelRequest.phone_mobile;
                    UpdEntity.department      = updateUserModelRequest.department;
                    UpdEntity.report_to_id    = updateUserModelRequest.report_to_id;
                    UpdEntity.primary_email   = updateUserModelRequest.primary_email;
                    UpdEntity.alternate_email = updateUserModelRequest.alternate_email;
                    UpdEntity.user_type       = updateUserModelRequest.user_type;
                    UpdEntity.user_status     = updateUserModelRequest.user_status;
                    UpdEntity.modified_date   = DateTime.Now;
                    UpdEntity.modifiedby_id   = updateUserModelRequest.modifiedby_id;

                    context.Entry(UpdEntity).State = EntityState.Modified;

                    context.SaveChanges();

                    SuiteWrapper.WriteTraceLog("User is Successfully updated.");
                    return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while updating the contact is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));;
            }
        }
        //Path: /api/User/CreateUser
        public HttpResponseMessage CreateUser(CreateUserModel CreateUserModelRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'CreateUser' with request :" + JsonConvert.SerializeObject(CreateUserModelRequest));
            PushUserResponse pushUserResponse = new PushUserResponse();

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(CreateUserModelRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(CreateUserModelRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    user userObject = new user();
                    userObject.user_name       = CreateUserModelRequest.user_name;
                    userObject.user_hash       = SuiteWrapper.CreateMD5(CreateUserModelRequest.user_hash);
                    userObject.first_name      = CreateUserModelRequest.first_name;
                    userObject.last_name       = CreateUserModelRequest.last_name;
                    userObject.phone_home      = CreateUserModelRequest.phone_home;
                    userObject.phone_mobile    = CreateUserModelRequest.phone_mobile;
                    userObject.department      = CreateUserModelRequest.department;
                    userObject.report_to_id    = CreateUserModelRequest.report_to_id;
                    userObject.primary_email   = CreateUserModelRequest.primary_email;
                    userObject.alternate_email = CreateUserModelRequest.alternate_email;
                    userObject.user_type       = CreateUserModelRequest.user_type;
                    userObject.user_status     = CreateUserModelRequest.user_status;
                    userObject.created_date    = DateTime.Now;
                    userObject.modified_date   = DateTime.Now;
                    userObject.createdby_id    = CreateUserModelRequest.createdby_id;
                    userObject.modifiedby_id   = CreateUserModelRequest.createdby_id;
                    context.users.Add(userObject);

                    context.SaveChanges();

                    pushUserResponse.id     = userObject.id;
                    pushUserResponse.status = "Success";

                    SuiteWrapper.WriteTraceLog("user is successfully created with response :" + JsonConvert.SerializeObject(pushUserResponse));
                    return(Request.CreateResponse(HttpStatusCode.OK, pushUserResponse));
                }
            }
            catch (Exception ex)
            {
                pushUserResponse.id     = null;
                pushUserResponse.status = ex.Message.ToString();

                SuiteWrapper.WriteTraceLog("Exception while creating user is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(pushUserResponse)));
            }
        }
        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("");
        }
예제 #17
0
        //Path: /api/Artist/CreateArtist
        public HttpResponseMessage CreateArtist(CreateArtist createArtistRequest)
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'CreateArtist' with request :" + JsonConvert.SerializeObject(createArtistRequest));
            CreateArtistResponse createArtistResponse = new CreateArtistResponse();

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(createArtistRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(createArtistRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    artist artistObject = new artist();
                    artistObject.name            = createArtistRequest.name;
                    artistObject.description     = createArtistRequest.description;
                    artistObject.year_of_birth_c = createArtistRequest.year_of_birth_c;
                    artistObject.year_of_death_c = createArtistRequest.year_of_death_c;
                    artistObject.status          = createArtistRequest.status;
                    artistObject.created_date    = DateTime.Now;
                    artistObject.modified_date   = DateTime.Now;
                    artistObject.createdby_id    = createArtistRequest.createdby_id;
                    artistObject.modifiedby_id   = createArtistRequest.createdby_id;
                    context.artists.Add(artistObject);

                    context.SaveChanges();

                    createArtistResponse.id     = artistObject.id;
                    createArtistResponse.status = "Success";

                    SuiteWrapper.WriteTraceLog("user is successfully created with response :" + JsonConvert.SerializeObject(createArtistResponse));
                    return(Request.CreateResponse(HttpStatusCode.OK, createArtistResponse));
                }
            }
            catch (Exception ex)
            {
                createArtistResponse.id     = null;
                createArtistResponse.status = ex.Message.ToString();

                SuiteWrapper.WriteTraceLog("Exception while creating artist is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(createArtistResponse)));
            }
        }
        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()));
            }
        }
예제 #19
0
        //Path: /api/Artist/UpdateArtist
        public HttpResponseMessage UpdateArtist(UpdateArtist updateArtistRequest)
        {
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'UpdateArtist' with request :" + JsonConvert.SerializeObject(updateArtistRequest));

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(updateArtistRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(updateArtistRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    var UpdEntity = context.artists.AsNoTracking().FirstOrDefault(m => m.id == updateArtistRequest.id);
                    if (UpdEntity == null)
                    {
                        SuiteWrapper.WriteTraceLog("Artist doesn't exist.");
                        return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Artist doesn't exist."));;
                    }


                    UpdEntity.name            = updateArtistRequest.name;
                    UpdEntity.description     = updateArtistRequest.description;
                    UpdEntity.year_of_birth_c = updateArtistRequest.year_of_birth_c;
                    UpdEntity.year_of_death_c = updateArtistRequest.year_of_death_c;
                    UpdEntity.status          = updateArtistRequest.status;
                    UpdEntity.modified_date   = DateTime.Now;
                    UpdEntity.modifiedby_id   = updateArtistRequest.modifiedby_id;

                    context.Entry(UpdEntity).State = EntityState.Modified;

                    context.SaveChanges();

                    SuiteWrapper.WriteTraceLog("Artist is Successfully updated.");
                    return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while updating the artist is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));;
            }
        }
        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 bool GetCustomer(string logId, DateTime startDate, DateTime endDate)
        {
            var customer = new GetCustomer();
            var resp     = customer.GetListofAMCustomer(startDate, endDate, logId);

            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Customer sync ended", Name = "GetCustomer", Entity_c = "Customer"
            }, logId);
            SuiteWrapper.WriteTraceLog("GetCustomer", "---------------- CUSTOMER SYNC END ------------------------- ");
            if (resp.StatusCode == 5)
            {
                return(true);
            }
            return(false);
        }
        //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()));
            }
        }
        public bool GetRegistration(string logId)
        {
            var registration = new GetRegistration();
            var resp         = registration.GetListofAMRegistration(logId);

            SuiteWrapper.WriteTraceLog("GetRegistration", "---------------- REGISTRATION SYNC END ------------------------- ");
            common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
            {
                Description = "Registration sync end", Name = "GetRegistration", Entity_c = "Registration"
            }, logId);

            if (resp.StatusCode == 5)
            {
                return(true);
            }
            return(false);
        }
예제 #24
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);
        }
 // *****************Check For Auction Avaliability ********************************************
 private bool CheckForAuctionAvailability(string auctionInternalId, string logId)
 {
     try
     {
         if (GetListSuiteAuctionCalender(auctionInternalId, logId) != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         SuiteWrapper.WriteTraceLog("CheckForAuctionAvailability", "Error Message : " + ex.Message);
         return(false);
     }
 }
        // ********************Check customer Registration for Auction *******************************
        private string CheckForRegistration(string auctionInternalId, SuiteContact suiteContact, string paddle, string auctionName, string logId)
        {
            var recordID        = "";
            var registerrequest = new CreateRegistrationRequest();

            registerrequest.Ac1_auction_calendar_id_c = auctionInternalId;
            registerrequest.Contact_id      = suiteContact.Id;
            registerrequest.Paddle_number_c = paddle;
            registerrequest.Name            = paddle + "-" + suiteContact.Name;

            try
            {
                var searchResultsRegistratioList = GetListSuiteRegistration(auctionInternalId, suiteContact.Id, logId);


                if (searchResultsRegistratioList != null && searchResultsRegistratioList.Count() > 0)
                {
                    foreach (var r in searchResultsRegistratioList)
                    {
                        registerrequest.Id = Convert.ToString(((Newtonsoft.Json.Linq.JProperty)r).Value);
                        recordID           = UpdateSuiteRegistration(registerrequest, logId);
                        return(registerrequest.Id);
                    }
                }
                else
                {
                    recordID           = InsertSuiteRegistration(registerrequest, logId);
                    registerrequest.Id = recordID;
                    recordID           = UpdateSuiteRegistration(registerrequest, logId);
                }
                return(recordID);
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("CheckForRegistration", "Error : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "CheckForRegistration", Entity_c = "Registration"
                }, logId);
                throw ex;
            }
        }
        // Get Auction Summary
        private AMCustomer.AMAuctionSummary GetAuctionSummary(string auctionID, string logId)
        {
            var amWrapper             = new AMWrapper();
            var ret                   = new GetListofAMAuctionResponse();
            var getListofAMAuctionReq = new GetListofAMAuctionRequest();

            ret.ReferenceID = getListofAMAuctionReq.ReferenceID;

            try
            {
                var req = new ReadEntryListRequest();
                req.AccessToken = req.AccessToken;
                req.ModuleName  = "auction";
                var auctionDetails         = amWrapper.GetAMList <AMCustomer.AMAuction>(req, $"{amWrapper.apiUrl}/v1/auction/" + auctionID + "/summary").GetAwaiter().GetResult();
                var result_page            = JObject.Parse(auctionDetails).SelectToken("response");
                var amAuctionSummaryRecord = new AMCustomer.AMAuctionSummary();

                amAuctionSummaryRecord.Row_id                = result_page.Value <string>("row_id");
                amAuctionSummaryRecord.Auction_type          = result_page.Value <string>("auction_type");
                amAuctionSummaryRecord.Time_start            = result_page.Value <string>("time_start");
                amAuctionSummaryRecord.Timezone              = result_page.Value <string>("timezone");
                amAuctionSummaryRecord.Auction_code          = result_page.Value <string>("auction_code");
                amAuctionSummaryRecord.Title                 = result_page.Value <string>("title");
                amAuctionSummaryRecord.Truncated_description = result_page.Value <string>("truncated_description");
                amAuctionSummaryRecord.Viewing_information   = result_page.Value <string>("viewing_information");
                amAuctionSummaryRecord.Currency_code         = result_page.Value <string>("currency_code");
                amAuctionSummaryRecord.Location_name         = result_page.Value <string>("location_name");

                return(amAuctionSummaryRecord);
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("GetAuctionSummary", "Error : " + ex.Message);
                common.InsertSuiteAmIntegrationLogDetail(new CreateTraceLogRequest()
                {
                    Description = "Error : " + ex.Message, Name = "GetAuctionSummary", Entity_c = "Registration"
                }, logId);
            }
            return(null);
        }
        public HttpResponseMessage GetDropdownMasterData()
        {
            // Trace Log
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'GetDropdownMasterData'");
            List <GetDropDownMasterData_Result> data = new List <GetDropDownMasterData_Result>();

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    data = context.GetDropDownMasterData().ToList();
                }
                SuiteWrapper.WriteTraceLog("Successfully called with response:" + JsonConvert.SerializeObject(data));
                return(Request.CreateResponse(HttpStatusCode.OK, data));
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while pulling the data is " + ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));
            }
        }
        //Path: /api/Contact/UpdateContact
        public HttpResponseMessage UpdateContact(ContactModel contactRequest)
        {
            File.AppendAllText(SuiteWrapper.traceLogPath, Environment.NewLine + Environment.NewLine);
            SuiteWrapper.WriteTraceLog("Called 'UpdateContact' with request :" + JsonConvert.SerializeObject(contactRequest));

            string outputMessage = string.Empty;

            if (!SuiteWrapper.ValidateRequest(contactRequest, out outputMessage))
            {
                //Trace Log
                SuiteWrapper.WriteTraceLog("Exception while validating request for " + JsonConvert.SerializeObject(contactRequest) + " is : " + outputMessage);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, outputMessage));;
            }

            try
            {
                using (PundolesEntities context = new PundolesEntities())
                {
                    var UpdEntity = context.contacts.AsNoTracking().FirstOrDefault(m => m.contact_id == contactRequest.contact_id);
                    if (UpdEntity == null)
                    {
                        SuiteWrapper.WriteTraceLog("Contact doesn't exist.");
                        return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Contact doesn't exist."));;
                    }

                    UpdEntity.salutation                = contactRequest.salutation;
                    UpdEntity.first_name                = contactRequest.first_name;
                    UpdEntity.last_name                 = contactRequest.last_name;
                    UpdEntity.company_name              = contactRequest.company_name;
                    UpdEntity.contact_type              = contactRequest.contact_type;
                    UpdEntity.client_number             = contactRequest.client_number;
                    UpdEntity.interest_id               = contactRequest.interest_id;
                    UpdEntity.category_id               = contactRequest.category_id;
                    UpdEntity.customer_category_id      = contactRequest.customer_category_id;
                    UpdEntity.level_id                  = contactRequest.level_id;
                    UpdEntity.catalogue_id              = contactRequest.catalogue_id;
                    UpdEntity.marital_status_id         = contactRequest.marital_status_id;
                    UpdEntity.marriage_anniversary_date = contactRequest.marriage_anniversary_date;
                    UpdEntity.am_customer_id            = contactRequest.am_customer_id;
                    UpdEntity.approval_status_id        = contactRequest.approval_status_id;
                    UpdEntity.authorized_to_bid_id      = contactRequest.authorized_to_bid_id;
                    UpdEntity.email                = contactRequest.email;
                    UpdEntity.phone                = contactRequest.phone;
                    UpdEntity.fax                  = contactRequest.fax;
                    UpdEntity.mobile               = contactRequest.mobile;
                    UpdEntity.other_phone          = contactRequest.other_phone;
                    UpdEntity.clients_vat_tin_no   = contactRequest.clients_vat_tin_no;
                    UpdEntity.aadhar_number        = contactRequest.aadhar_number;
                    UpdEntity.pan_no               = contactRequest.pan_no;
                    UpdEntity.date_modified        = DateTime.Now;
                    UpdEntity.modifiedby_id        = contactRequest.modifiedby_id;
                    context.Entry(UpdEntity).State = EntityState.Modified;

                    context.SaveChanges();

                    SuiteWrapper.WriteTraceLog("Successfully called");
                    return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
                }
            }
            catch (Exception ex)
            {
                SuiteWrapper.WriteTraceLog("Exception while updating the contact is : " + ex.Message.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString()));;
            }
        }
        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()));
            }
        }