public CRMUserAuthenticateModel LoadDetailsDotsCommon(string serverUrl, string orgName) { var model = new CRMUserAuthenticateModel(); var result = Obj.tbl_Configuration.SingleOrDefault(o => o.ServerUrl.ToLower() == serverUrl.ToLower() && o.OrgUniqueName.ToLower() == orgName); if (result != null) { model.Id = result.Id; model.FirstName = result.FirstName; model.LastName = result.LastName; model.Company = result.Company; model.ContactNo = result.ContactNo; model.Email = result.Email; model.Address = result.Address; model.Country = result.Country; model.State = result.State; model.City = result.City; model.PostalCode = result.PostalCode; model.UserName = result.UserName; model.Password = "******"; model.SubscriptionType = result.SubscriptionType; model.ExpireDate = result.ExpireDate.Date; model.IsSuccess = true; return(model); } else { model.IsSuccess = false; return(model); } }
public CRMUserAuthenticateModel LoadDetails(string registerId) { var model = new CRMUserAuthenticateModel(); Guid Id = Guid.Empty; if (registerId != null) { Id = Guid.Parse(registerId); } var result = Obj.tbl_Configuration.SingleOrDefault(o => o.Id == Id); if (result != null) { model.FirstName = result.FirstName; model.LastName = result.LastName; model.Company = result.Company; model.ContactNo = result.ContactNo; model.Email = result.Email; model.Address = result.Address; model.Country = result.Country; model.State = result.State; model.City = result.City; model.PostalCode = result.PostalCode; model.UserName = result.UserName; model.Password = "******"; model.SubscriptionType = result.SubscriptionType; model.ExpireDate = result.ExpireDate.Date; model.IsSuccess = true; return(model); } else { model.IsSuccess = false; return(model); } }
public CRMUserAuthenticateModel UserAuthenticate(string FirstName, string LastName, string Company, string ContactNo, string Email, string Address, string Country, string State, string City, string PostalCode, string SubscriptionType, string orgName, string ServerUrl, string UserName, string Password, string RegisterId) { //string orgName = paramsObject.orgName; //string UserName = paramsObject.UserName; //string Password = paramsObject.Password; // String _discoveryServiceAddress = "https://disco.crm8.dynamics.com/XRMServices/2011/Discovery.svc"; // String _organizationUniqueName = "orgb51959c4"; //// Provide your user name and password. // String _userName = "******"; // String _password = "******"; //// Provide domain name for the On-Premises org. // String _domain = "mydomain"; string finalUrl = ""; var strorgName = ServerUrl.Split('.'); if (strorgName.Contains("api")) { finalUrl = strorgName[2] + "." + strorgName[3] + "." + strorgName[4].Replace("\"", ""); } else { finalUrl = strorgName[1] + "." + strorgName[2] + "." + strorgName[3].Replace("\"", ""); } // for uk String _discoveryServiceAddress = "https://disco." + finalUrl + "/XRMServices/2011/Discovery.svc"; String _organizationUniqueName = orgName; // Provide your user name and password. String _userName = UserName; String _password = Password; // Provide domain name for the On-Premises org. String _domain = "mydomain"; //var model = new UserAuthenticateModel(); var model = new CRMUserAuthenticateModel(); try { //CrmConnection connection = CrmConnection.Parse(PortalPage.GetServiceConfiguration()); IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(_discoveryServiceAddress)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType, _userName, _password, _domain); //for stop 5 second to response some server System.Threading.Thread.Sleep(5000); String organizationUri = String.Empty; // Get the discovery service proxy. using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials)) { // Obtain organization information from the Discovery service. if (discoveryProxy != null) { // Obtain information about the organizations that the system user belongs to. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); // Obtains the Web address (Uri) of the target organization. organizationUri = FindOrganization(_organizationUniqueName, orgs.ToArray()).Endpoints[EndpointType.OrganizationService]; } } if (!String.IsNullOrWhiteSpace(organizationUri)) { IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>( new Uri(organizationUri)); // Set the credentials. AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType, _userName, _password, _domain); // Get the organization service proxy. using (OrganizationServiceProxy organizationProxy = GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials)) { // This statement is required to enable early-bound type support. organizationProxy.EnableProxyTypes(); // Now make an SDK call with the organization service proxy. // Display information about the logged on user. Guid userid = ((WhoAmIResponse)organizationProxy.Execute( new WhoAmIRequest())).UserId; SystemUser systemUser = organizationProxy.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" })).ToEntity <SystemUser>(); //Console.WriteLine("Logged on user is {0} {1}.", // systemUser.FirstName, systemUser.LastName); Guid registerId = Guid.Empty; if (RegisterId != null) { registerId = Guid.Parse(RegisterId); } tbl_Configuration tblConfig = new tbl_Configuration(); var update = Obj.tbl_Configuration.SingleOrDefault(o => o.Id == registerId); if (update != null) { update.FirstName = FirstName; update.LastName = LastName; update.Company = Company; update.ContactNo = ContactNo; update.Email = Email; update.Address = Address; update.Country = Country; update.State = State; update.City = City; update.PostalCode = PostalCode; update.UserName = UserName; update.Password = Password; update.OrgUniqueName = orgName; update.ServerUrl = ServerUrl; update.SubscriptionType = SubscriptionType; update.SolutionName = "LeadCreation"; update.ModifyDate = DateTime.Now; update.IsCreated = false; // tblConfig.ExpireDate = DateTime.Now.AddDays(trialTimePeriodInDays); Obj.SaveChanges(); } else { tblConfig.Id = Guid.NewGuid(); tblConfig.FirstName = FirstName; tblConfig.LastName = LastName; tblConfig.Company = Company; tblConfig.ContactNo = ContactNo; tblConfig.Email = Email; tblConfig.Address = Address; tblConfig.Country = Country; tblConfig.State = State; tblConfig.City = City; tblConfig.PostalCode = PostalCode; tblConfig.UserName = UserName; tblConfig.Password = Password; tblConfig.OrgUniqueName = orgName; tblConfig.ServerUrl = ServerUrl; tblConfig.SubscriptionType = SubscriptionType; tblConfig.SolutionName = "LeadCreation"; tblConfig.CreateDate = DateTime.Now; tblConfig.ModifyDate = null; tblConfig.ExpireDate = DateTime.Now.AddDays(trialTimePeriodInDays); tblConfig.IsCreated = true; Obj.tbl_Configuration.Add(tblConfig); Obj.SaveChanges(); } //return model string EncrypyUserName = "", EncryptPassword = ""; Guid Id = Guid.Empty; if (update != null) { model.Id = update.Id; model.IsCreated = update.IsCreated; } else { model.Id = tblConfig.Id; model.IsCreated = tblConfig.IsCreated; } model.FirstName = FirstName; model.LastName = LastName; model.Company = Company; model.ContactNo = ContactNo; model.Email = Email; model.Address = Address; model.Country = Country; model.State = State; model.City = City; model.PostalCode = PostalCode; if (UserName != null) { EncrypyUserName = EncryptString(UserName, "@123"); } if (Password != null) { EncryptPassword = EncryptString(Password, "@123"); } model.UserName = EncrypyUserName; model.EPassword = EncryptPassword; model.SubscriptionType = SubscriptionType; model.IsSuccess = true; } } return(model); } catch (Exception ex) { model.IsSuccess = false; model.Error = ex.Message; return(model); } }
public CRMUserAuthenticateModel DotsCommon(string FirstName, string LastName, string Company, string ContactNo, string Email, string Address, string Country, string State, string City, string PostalCode, string SubscriptionType, string orgName, string ServerUrl, string UserName, string Password, string SName) { var model = new CRMUserAuthenticateModel(); try { tbl_Configuration tblConfig = new tbl_Configuration(); //always return null var update = Obj.tbl_Configuration.SingleOrDefault(o => o.ServerUrl.ToLower() == ServerUrl.ToLower() && o.OrgUniqueName.ToLower() == orgName.ToLower() && o.SolutionName == "####"); if (update != null) { update.FirstName = FirstName; update.LastName = LastName; update.Company = Company; update.ContactNo = ContactNo; update.Email = Email; update.Address = Address; update.Country = Country; update.State = State; update.City = City; update.PostalCode = PostalCode; update.UserName = UserName; update.Password = Password; update.OrgUniqueName = orgName; update.ServerUrl = ServerUrl; update.SubscriptionType = SubscriptionType; update.ModifyDate = DateTime.Now; update.IsCreated = false; // tblConfig.ExpireDate = DateTime.Now.AddDays(trialTimePeriodInDays); Obj.SaveChanges(); } else { tblConfig.Id = Guid.NewGuid(); tblConfig.FirstName = FirstName; tblConfig.LastName = LastName; tblConfig.Company = Company; tblConfig.ContactNo = ContactNo; tblConfig.Email = Email; tblConfig.Address = Address; tblConfig.Country = Country; tblConfig.State = State; tblConfig.City = City; tblConfig.PostalCode = PostalCode; tblConfig.UserName = UserName; tblConfig.Password = Password; tblConfig.OrgUniqueName = orgName; tblConfig.ServerUrl = ServerUrl; tblConfig.SubscriptionType = SubscriptionType; tblConfig.SolutionName = SName; tblConfig.CreateDate = DateTime.Now; tblConfig.ModifyDate = null; tblConfig.ExpireDate = DateTime.Now.AddDays(trialTimePeriodInDays); tblConfig.IsCreated = true; Obj.tbl_Configuration.Add(tblConfig); Obj.SaveChanges(); } //return model if (update != null) { model.Id = update.Id; model.IsCreated = update.IsCreated; } else { model.Id = tblConfig.Id; model.IsCreated = tblConfig.IsCreated; } model.FirstName = FirstName; model.LastName = LastName; model.Company = Company; model.ContactNo = ContactNo; model.Email = Email; model.Address = Address; model.Country = Country; model.State = State; model.City = City; model.PostalCode = PostalCode; model.UserName = UserName; model.Password = Password; model.SubscriptionType = SubscriptionType; model.SolutionName = SName; model.IsSuccess = true; return(model); } catch (Exception ex) { model.IsSuccess = false; model.Error = ex.Message; return(model); } }
public CRMUserAuthenticateModel DataInsertTimeUserAuthenticate(string orgName, string ServerUrl, string UserName, string Password) { // String _discoveryServiceAddress = "https://disco.crm8.dynamics.com/XRMServices/2011/Discovery.svc"; // String _organizationUniqueName = "orgb51959c4"; //// Provide your user name and password. // String _userName = "******"; // String _password = "******"; //// Provide domain name for the On-Premises org. // String _domain = "mydomain"; string finalUrl = ""; var strorgName = ServerUrl.Split('.'); if (strorgName.Contains("api")) { finalUrl = strorgName[2] + "." + strorgName[3] + "." + strorgName[4].Replace("\"", ""); } else { finalUrl = strorgName[1] + "." + strorgName[2] + "." + strorgName[3].Replace("\"", ""); } // for uk String _discoveryServiceAddress = "https://disco." + finalUrl + "/XRMServices/2011/Discovery.svc"; String _organizationUniqueName = orgName; // Provide your user name and password. String _userName = UserName; String _password = Password; // Provide domain name for the On-Premises org. String _domain = "mydomain"; //var model = new UserAuthenticateModel(); var model = new CRMUserAuthenticateModel(); try { //CrmConnection connection = CrmConnection.Parse(PortalPage.GetServiceConfiguration()); IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>( new Uri(_discoveryServiceAddress)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType, _userName, _password, _domain); String organizationUri = String.Empty; // Get the discovery service proxy. using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials)) { // Obtain organization information from the Discovery service. if (discoveryProxy != null) { // Obtain information about the organizations that the system user belongs to. OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy); // Obtains the Web address (Uri) of the target organization. organizationUri = FindOrganization(_organizationUniqueName, orgs.ToArray()).Endpoints[EndpointType.OrganizationService]; } } if (!String.IsNullOrWhiteSpace(organizationUri)) { IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>( new Uri(organizationUri)); // Set the credentials. AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType, _userName, _password, _domain); // Get the organization service proxy. using (OrganizationServiceProxy organizationProxy = GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials)) { // This statement is required to enable early-bound type support. organizationProxy.EnableProxyTypes(); // Now make an SDK call with the organization service proxy. // Display information about the logged on user. Guid userid = ((WhoAmIResponse)organizationProxy.Execute( new WhoAmIRequest())).UserId; SystemUser systemUser = organizationProxy.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" })).ToEntity <SystemUser>(); //Console.WriteLine("Logged on user is {0} {1}.", // systemUser.FirstName, systemUser.LastName); model.FirstName = systemUser.FirstName; model.LastName = systemUser.LastName; model.IsSuccess = true; } } return(model); } catch (Exception ex) { model.IsSuccess = false; model.Error = ex.Message; return(model); } }