//This Methos find XeroModel Contact given by Guid public XeroApi.Model.Contact findContact(Repository repos, String strGuid) { XeroApi.Model.Contact deltoneContact = new XeroApi.Model.Contact(); var Deltonecontact = repos.Contacts.Where(Contact => Contact.ContactID == Guid.Parse(strGuid)).ToList(); foreach (var contact in Deltonecontact) { deltoneContact = (XeroApi.Model.Contact)contact; } return(deltoneContact); }
protected void Page_Load(object sender, EventArgs e) { contactdal = new ContactDAL(CONNSTRING); xero = new XeroIntergration(); int CompID = Int32.Parse(Request.Form["CompID"].ToString()); String FirstName = Request.Form["NewFirstName"].ToString(); String LastName = Request.Form["NewLastName"].ToString(); String DefaultAreaCode = Request.Form["NewDefaultAreaCode"].ToString(); String DefaultNumber = Request.Form["NewDefaultNumber"].ToString(); String MobileNumber = Request.Form["NewMobileNumber"].ToString(); String EmailAddy = Request.Form["NewEmailAddy"].ToString(); String ShipLine1 = Request.Form["NewShipLine1"].ToString(); String ShipLine2 = Request.Form["NewShipLine2"].ToString(); String ShipCity = Request.Form["NewShipCity"].ToString(); String ShipState = Request.Form["NewShipState"].ToString(); String ShipPostcode = Request.Form["NewShipPostcode"].ToString(); String BillLine1 = Request.Form["NewBillLine1"].ToString(); String BillLine2 = Request.Form["NewBillLine2"].ToString(); String BillCity = Request.Form["NewBillCity"].ToString(); String BillState = Request.Form["NewBillState"].ToString(); String BillPostcode = Request.Form["NewBillPostcode"].ToString(); String PrimaryContact = Request.Form["PrimaryContact"].ToString(); String finalPrimaryContact = ""; if (PrimaryContact == "true") { finalPrimaryContact = "Y"; } else { finalPrimaryContact = "N"; } DeltoneCRMDAL dal = new DeltoneCRMDAL(); // Response.Write(dal.AddNewContact(CompID, FirstName, LastName, DefaultAreaCode, DefaultNumber, MobileNumber, EmailAddy, ShipLine1, ShipLine2, ShipCity, ShipState, ShipPostcode, BillLine1, BillLine2, BillCity, BillState, BillPostcode, finalPrimaryContact)); var loggedInUserId = Convert.ToInt32(Session["LoggedUserID"].ToString()); String str = dal.AddNewContact(CompID, FirstName, LastName, DefaultAreaCode, DefaultNumber, MobileNumber, EmailAddy, ShipLine1, ShipLine2, ShipCity, ShipState, ShipPostcode, BillLine1, BillLine2, BillCity, BillState, BillPostcode, finalPrimaryContact, loggedInUserId); if (!String.IsNullOrEmpty(str)) { String[] arr = str.Split(':'); String contactID = arr[1].ToString(); String companyname = arr[2].ToString(); String companywebsite = arr[3].ToString(); String strDefaultCountryCode = "+61"; //Should have entries in AddContactUI String strDefaultCountry = "Australia"; //Should have entries in AddContactUI //Create the Repository Repository res = xero.CreateRepository(); XeroApi.Model.Contact delContact = xero.CreateContact(res, companyname, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, BillPostcode, BillState); if (delContact != null) { //Update the ContactGuid in the DataBase Table contactdal.UpdateWithXeroDetails(CompID, delContact.ContactID.ToString()); } else { } Response.Write(str); } }
//This Function Create a Contact In the Xero System public XeroApi.Model.Contact CreateContact(Repository repos, String strCompnayName, String strFirstName, String strLastName, String strDefaultAreadCode, String strDefaultCountryCode, String strDefaultNumber, String strFaxAreaCode, String strFaxCountryCode, String strFaxNumber, String strMobileAreaCode, String strMobileCountryCode, String strMobileNumber, String strEmail, String strStreetAddressLine1, String strStreetCity, String strSteetCountry, String strStreetPostalCode, String strStreetRegion, String strPostalAddressLine1, String strPostalCity, String strPostalCountry, String strPostalCode, String strPostalRegion) { XeroApi.Model.Contact DeltoneContact = new XeroApi.Model.Contact(); try { DeltoneContact.Name = strCompnayName; //Company Name DeltoneContact.FirstName = strFirstName; //First Name of the Compnay Contact DeltoneContact.LastName = strLastName; //Last name of the Compnay Contact DeltoneContact.EmailAddress = strEmail; //Email of the Company Contact DeltoneContact.ContactStatus = "ACTIVE"; //(ACTIVE,ARCHIVED) DeltoneContact.IsCustomer = true; //Define Default Phone Number XeroApi.Model.Phone Default_phone = new XeroApi.Model.Phone(); Default_phone.PhoneType = "DEFAULT"; Default_phone.PhoneAreaCode = strDefaultAreadCode; Default_phone.PhoneCountryCode = strDefaultCountryCode; Default_phone.PhoneNumber = strDefaultNumber; //Define Mobile phone Number XeroApi.Model.Phone Mobile = new XeroApi.Model.Phone(); Mobile.PhoneType = "MOBILE"; Mobile.PhoneAreaCode = strMobileAreaCode; Mobile.PhoneCountryCode = strMobileCountryCode; Mobile.PhoneNumber = strMobileNumber; //Define Fax Number XeroApi.Model.Phones deltonePhones = new XeroApi.Model.Phones(); deltonePhones.Add(Default_phone); deltonePhones.Add(Mobile); DeltoneContact.Phones = deltonePhones; //Define Street Address here XeroApi.Model.Addresses deltone_Address = new Addresses(); XeroApi.Model.Address street_Address = new XeroApi.Model.Address(); street_Address.AddressType = "STREET"; street_Address.AddressLine1 = strStreetAddressLine1; street_Address.City = strStreetCity; street_Address.Country = strSteetCountry; street_Address.PostalCode = strStreetPostalCode; street_Address.Region = strStreetPostalCode; //Define Postal Address here XeroApi.Model.Address postal_Address = new XeroApi.Model.Address(); postal_Address.AddressType = "POBOX"; postal_Address.AddressLine1 = strPostalAddressLine1; postal_Address.City = strPostalCity; postal_Address.Country = strPostalCountry; postal_Address.PostalCode = strPostalCode; postal_Address.Region = strPostalRegion; deltone_Address.Add(street_Address); deltone_Address.Add(postal_Address); DeltoneContact.Addresses = deltone_Address; var createdContact = repos.Create(DeltoneContact); //Check wether Validation Errors Exsists or Not if (createdContact.ValidationStatus == XeroApi.Model.ValidationStatus.ERROR) { foreach (var message in createdContact.ValidationErrors) { Console.WriteLine("Validation Error: " + message.Message); } return(null); } return((XeroApi.Model.Contact)createdContact); } catch (Exception ex) { ex.StackTrace.ToString(); return(null); } }
protected void Page_Load(object sender, EventArgs e) { xero = new XeroIntergration(); ContactDAL contactdal = new ContactDAL(strConnString); CompanyDAL companydal = new CompanyDAL(strConnString); int ContactID = Int32.Parse(Request.Form["ContactID"].ToString()); String FirstName = Request.Form["NewFirstName"].ToString(); String LastName = Request.Form["NewLastName"].ToString(); String DefaultAreaCode = Request.Form["NewDefaultAreaCode"].ToString(); String DefaultNumber = Request.Form["NewDefaultNumber"].ToString(); String MobileNumber = Request.Form["NewMobileNumber"].ToString(); String EmailAddy = Request.Form["NewEmailAddy"].ToString(); String ShipLine1 = Request.Form["NewShipLine1"].ToString(); String ShipLine2 = Request.Form["NewShipLine2"].ToString(); String ShipCity = Request.Form["NewShipCity"].ToString(); String ShipState = Request.Form["NewShipState"].ToString(); String ShipPostcode = Request.Form["NewShipPostcode"].ToString(); String BillLine1 = Request.Form["NewBillLine1"].ToString(); String BillLine2 = Request.Form["NewBillLine2"].ToString(); String BillCity = Request.Form["NewBillCity"].ToString(); String BillState = Request.Form["NewBillState"].ToString(); String BillPostcode = Request.Form["NewBillPostcode"].ToString(); String PrimaryContact = Request.Form["PrimaryContact"].ToString(); String ActINact = Request.Form["ActInact"].ToString(); string finalActInact = ""; if (ActINact == "false") { finalActInact = "N"; } else { finalActInact = "Y"; } String finalPrimaryContact = ""; if (PrimaryContact == "true") { finalPrimaryContact = "Y"; } else { finalPrimaryContact = "N"; } var userId = Convert.ToInt32(Session["LoggedUserID"].ToString()); String str = contactdal.UpdateContact(ContactID, FirstName, LastName, DefaultAreaCode, DefaultNumber, MobileNumber, EmailAddy, ShipLine1, ShipLine2, ShipCity, ShipState, ShipPostcode, BillLine1, BillLine2, BillCity, BillState, BillPostcode, finalPrimaryContact, finalActInact, userId); if (Int32.Parse(str) > 0) { //Ge the XeroGuid and Update the Details in Xero String contactGuid = contactdal.getXeroGuid_ForContact(ContactID); if (!String.IsNullOrEmpty(contactGuid) && !(DBNull.Value.Equals(contactGuid))) { //Fetch the CompanyName for the Contact String strCompanyName = companydal.GetCompanybyContactID(ContactID); String strDefaultCountryCode = "+61"; //Should have entries in AddContactUI String strDefaultCountry = "Australia"; //Should have entries in AddContactUI Repository res = xero.CreateRepository();//Create the Repository XeroApi.Model.Contact delContact = xero.UpdateContact(res, contactGuid, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, ShipPostcode, BillState); if (delContact != null) { } // Repository res = xero.CreateRepository(); // XeroApi.Model.Contact delContact = xero.CreateContact(res, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, BillPostcode, BillState); //if (delContact != null) // { //Update the ContactGuid in the DataBase Table // contactdal.UpdateWithXeroDetails(23538, delContact.ContactID.ToString()); // } } else { //Entry hasn't been created in the Xero System .Create the Entry and Update the Tables } } Response.Write(str); }