public void InsertOrUpdateContactXero(string typeAction, SupplierModels model, string SupplierId) { var xeroInfo = Commons.GetIntegrateInfoWithComId(model.CompanyId); if (xeroInfo != null) { SupplierXeroFactory _facSupplier = new SupplierXeroFactory(); var modelsXero = new SupplierXeroModels() { AppRegistrationId = xeroInfo.ThirdPartyID, StoreId = xeroInfo.IPAddress, Contact = new ContactModels { ContactID = typeAction.Equals("update") ? model.Id : "", Name = model.Name, EmailAddress = model.Email, BankAccountDetails = "", IsSupplier = true, IsCustomer = false, HasAttachments = false, Addresses = new List <AddressesModels> { new AddressesModels { AddressType = 1, City = model.City, Country = model.Country, PostalCode = model.ZipCode, Region = "", } }, Phones = new List <PhonesModels> { new PhonesModels { PhoneType = 1, PhoneNumber = model.Phone1, PhoneAreaCode = "", PhoneCountryCode = "", }, new PhonesModels { PhoneType = 1, PhoneNumber = model.Phone2, PhoneAreaCode = "", PhoneCountryCode = "", } }, UpdatedDateUTC = DateTime.Now }, }; var msgXero = string.Empty; var resultXero = _facSupplier.CreateOrUpdateSupplier(xeroInfo.ApiURL, modelsXero, SupplierId, ref msgXero); } }
public bool CreateOrUpdateSupplier(string url, SupplierXeroModels models, string SupplierId, ref string msg) { try { SupplierXeroRequestModels paraBody = new SupplierXeroRequestModels(); paraBody.AccessToken = models.AccessToken; paraBody.AppRegistrationId = models.AppRegistrationId; paraBody.StoreId = models.StoreId; paraBody.Contact = models.Contact; NSLog.Logger.Info("CreateOrUpdateSupplier_Request:", paraBody); var result = (ResponseApiModels)ApiResponseXero.Post <ResponseApiModels>(url + "/" + Commons.XeroApi_InsertOrUpdateSupplier, null, paraBody); if (result.Success) { dynamic RawData = result.RawData; var content = JsonConvert.SerializeObject(RawData); SupplierXeroResponseModels data = JsonConvert.DeserializeObject <SupplierXeroResponseModels>(content); string ContactID = data.ContactID; //----Update XeroId for Supplier using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var itemUpdate = (from tb in cxt.I_Supplier where tb.Id == SupplierId select tb).FirstOrDefault(); if (itemUpdate != null) { itemUpdate.XeroId = ContactID; cxt.SaveChanges(); transaction.Commit(); } } catch (Exception ex) { NSLog.Logger.Error("UpdateXeroIdSupplier|Error: ", ex); transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } NSLog.Logger.Info("CreateOrUpdateSupplier_Response: ", data); return(true); } else { NSLog.Logger.Info("CreateOrUpdateSupplier|Result[False]|Message: ", result.Message); msg = result.Message; msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msg); return(false); } } catch (Exception ex) { NSLog.Logger.Error("CreateOrUpdateSupplier|Error: ", ex); return(false); } }