var personIdentity = new IdentityServiceReference.PersonInfo() { CrmId = null, Categories = new IdentityServiceReference.CategoryInfo[] { new IdentityServiceReference.CategoryInfo() { Key = "WebsiteCustomers" } }, CrmObjectTypeCode = "person", CrmObjectTypeIndex = 24, Emails = new string[] { Customer.EmailAddress }, FirstName = Customer.FirstName, LastName = Customer.LastName, Gender = Customer.Gender == Gender.MALE ? "مرد" : "زن", IdentityType = "حقیقی", PhoneContacts = Customer.Phones.Select(a => new IdentityServiceReference.IdentityContactPhone() { Id = a.Id, PhonePrefix = a.PhonePrefix, PhoneNumber = a.PhoneNumber, ContinuedNumber = a.ContinuedNumber, PhoneType = a.IsMobile ? "موبایل" : "تلفن", IsDefault = false, Extension = a.Internal }).ToArray(), AddressContacts = Customer.Addresses.Select(a => new IdentityServiceReference.IdentityContactAddress() { Id = a.Id, Country = "ایران", State = a.State, City = a.City, ZipCode = a.PostalCode, IsDefault = false, Address = a.PostalAddress, AddressType = "شعبه", ZipBox = a.LocationLatitude.HasValue ? (a.LocationLatitude.Value + "," + a.LocationLongitude.Value) : "" }).ToArray(), CustomerDate = DateTime.Now, OtherUsername = "Admin", SaleUsername = "Admin", SupportUsername = "Admin", SourceType = "وبسایت", }; var personResult = identityClient.SaveIdentity(UserName, Password, personIdentity); if (!personResult.Success) return new ResultState() { Success = false, Message = personResult.Message }; if (Customer.CustomerType == PersonType.LEGAL) { var organIdentity = new IdentityServiceReference.OrganizationInfo() { CrmId = null, Categories = new IdentityServiceReference.CategoryInfo[] { new IdentityServiceReference.CategoryInfo() { Key = "WebsiteCustomers" } }, CrmObjectTypeCode = "organization", CrmObjectTypeIndex = 24, Emails = new string[] { Customer.EmailAddress }, IdentityType = "حقوقی", NickName = Customer.CompanyName, PhoneContacts = Customer.Phones.Select(a => new IdentityServiceReference.IdentityContactPhone() { Id = a.Id, PhonePrefix = a.PhonePrefix, PhoneNumber = a.PhoneNumber, ContinuedNumber = a.ContinuedNumber, PhoneType = a.IsMobile ? "موبایل" : "تلفن", IsDefault = false, Extension = a.Internal }).ToArray(), AddressContacts = Customer.Addresses.Select(a => new IdentityServiceReference.IdentityContactAddress() { Id = a.Id, Country = "ایران", State = a.State, City = a.City, ZipCode = a.PostalCode, IsDefault = false, Address = a.PostalAddress, AddressType = "شعبه", ZipBox = a.LocationLatitude.HasValue ? (a.LocationLatitude.Value + "," + a.LocationLongitude.Value) : "" }).ToArray(), CustomerDate = DateTime.Now, OtherUsername = "Admin", SaleUsername = "Admin", SupportUsername = "Admin", SourceType = "وبسایت", ExtendedProperties = legalExtendedProperties }; var organResult = identityClient.SaveIdentity(UserName, Password, organIdentity); if (!organResult.Success) return new ResultState() { Success = false, Message = result.Message }; organIdentity.CrmId = organResult.CrmId; organIdentity.Personnel = new[] { new EmployeeInfo() { Department = "", Office = "", Profession = "", JobType = "کارمند", PersonId = personResult.CrmId, OrganizationId = organResult.CrmId }, }; var updateOrganResult = identityClient.SaveIdentity(UserName, Password, organIdentity); return new ResultState() { Success = true, Message = "", Data = organResult.CrmId }; }