public MsCrmResultObj <AssemblerInfo> GetUser(string token, string emailaddress, string password) { MsCrmResultObj <AssemblerInfo> returnValue = new MsCrmResultObj <AssemblerInfo>(); LoginSession ls = new LoginSession(); try { #region | CHECK SESSION | MsCrmResultObj <LoginSession> sessionResult = GetUserSession(token); if (!sessionResult.Success) { returnValue.Result = sessionResult.Result; return(returnValue); } else { ls = sessionResult.ReturnObject; } #endregion _sda = new SqlDataAccess(); _sda.openConnection(Globals.ConnectionString); returnValue = AssemblyRequestHelper.GetAssemblerInfo(emailaddress, password, _sda); } catch (Exception ex) { returnValue.HasException = true; returnValue.Result = ex.Message; } finally { if (_sda != null) { _sda.closeConnection(); } } return(returnValue); }
public void Execute(IServiceProvider serviceProvider) { SqlDataAccess sda = null; try { sda = new SqlDataAccess(); sda.openConnection(Globals.ConnectionString); #region | SERVICE | IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); #region | Validate Request | //Target yoksa veya Entity tipinde değilse, devam etme. if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity)) { return; } #endregion IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); #endregion Entity entity = (Entity)context.InputParameters["Target"]; #region |DEFINE IMAGE IF EXISTS| Entity preImage = null; if (context.PreEntityImages.Contains("PreImage") && context.PreEntityImages["PreImage"] is Entity) { preImage = (Entity)context.PreEntityImages["PreImage"]; } #endregion #region | VARIABLES | string customerFirstName = null; string customerLastName = null; string customerMobilePhone = null; string customerFullName = null; string assemblerFullName = null; int statusCode = 0; int oldStatusCode = 0; AssemblerInfo assemblerInfo = null; List <ScoreLimit> lstLimits = new List <ScoreLimit>(); EntityReference portal = null; EntityReference user = null; if (preImage.Contains("new_portalid") && preImage["new_portalid"] != null) { portal = (EntityReference)preImage["new_portalid"]; } if (preImage.Contains("new_userid") && preImage["new_userid"] != null) { user = (EntityReference)preImage["new_userid"]; MsCrmResultObj <AssemblerInfo> resultAssembler = AssemblyRequestHelper.GetAssemblerInfo(user.Id, sda); if (resultAssembler.Success) { assemblerInfo = resultAssembler.ReturnObject; } else { throw new Exception("Anahtarcı bilgisi alınamadı.Hata:" + resultAssembler.Result); } } if (preImage.Contains("new_firstname") && preImage["new_firstname"] != null) { customerFirstName = preImage["new_firstname"].ToString(); } if (preImage.Contains("new_lastname") && preImage["new_lastname"] != null) { customerLastName = preImage["new_lastname"].ToString(); } if (preImage.Contains("new_mobilephone") && preImage["new_mobilephone"] != null) { customerMobilePhone = preImage["new_mobilephone"].ToString(); } if (!string.IsNullOrWhiteSpace(customerFirstName) && !string.IsNullOrWhiteSpace(customerLastName)) { customerFullName = customerFirstName + " " + customerLastName; } if (entity.Contains("statuscode") && entity["statuscode"] != null) { statusCode = ((OptionSetValue)entity["statuscode"]).Value; } if (preImage.Contains("statuscode") && preImage["statuscode"] != null) { oldStatusCode = ((OptionSetValue)preImage["statuscode"]).Value; } #endregion if (statusCode != oldStatusCode && (statusCode == (int)DiscoveryFormStatus.CrmConfirmed || statusCode == (int)DiscoveryFormStatus.Result_Negative)) { string statusText = string.Empty; if (statusCode == (int)DiscoveryFormStatus.CrmConfirmed) { statusText = "Kale Onayladı"; } else if (statusCode == (int)DiscoveryFormStatus.Result_Negative) { statusText = "Sonuç Olumsuz"; } string customerSmsText = @"Sayın {0}, {1} müşterisine ait Ücretsiz Keşif Formu durumu {2} olarak değişmiştir. Bilgilerinize."; Entity ent = new Entity("new_sms"); ent["new_message"] = string.Format(customerSmsText, assemblerFullName, customerFullName, statusText); ent["new_phonenumber"] = assemblerInfo.MobilePhoneNumber; ent["new_name"] = customerFirstName + " " + customerLastName + "|KGS Formu Durum Değişimi"; ent["new_userid"] = user; service.Create(ent); } if (entity.Contains("statuscode") && entity["statuscode"] != null && ((OptionSetValue)entity["statuscode"]).Value == (int)DiscoveryFormStatus.CrmConfirmed) { MsCrmResultObject limitRes = ScoreHelper.GetScoreLimitsByType(ScoreType.KGSSales, sda); if (limitRes.Success) { lstLimits = (List <ScoreLimit>)limitRes.ReturnObject; for (int i = 0; i < lstLimits.Count; i++) { Score sc = new Score() { Point = lstLimits[i].Point, Portal = portal, User = user, ScoreType = ScoreType.KGSSales }; MsCrmResult scoreRes = ScoreHelper.CreateScore(sc, service); if (scoreRes.Success) { break; } } } } } catch (Exception ex) { //LOG throw new InvalidPluginExecutionException(ex.Message); } finally { if (sda != null) { sda.closeConnection(); } } }
public void Execute(IServiceProvider serviceProvider) { SqlDataAccess sda = null; try { sda = new SqlDataAccess(); sda.openConnection(Globals.ConnectionString); #region | SERVICE | IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); #region | Validate Request | //Target yoksa veya Entity tipinde değilse, devam etme. if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity)) { return; } #endregion IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); #endregion Entity entity = (Entity)context.InputParameters["Target"]; #region | VARIABLES | EntityReference userId = null; EntityReference cityId = null; EntityReference townId = null; AssemblerInfo assemblerInfo = null; string customerFirstName = null; string customerLastName = null; string customerMobilePhone = null; string customerFullName = null; string assemblerFullName = null; if (entity.Contains("new_userid") && entity["new_userid"] != null) { userId = (EntityReference)entity["new_userid"]; MsCrmResultObj <AssemblerInfo> resultAssembler = AssemblyRequestHelper.GetAssemblerInfo(userId.Id, sda); if (resultAssembler.Success) { assemblerInfo = resultAssembler.ReturnObject; } else { throw new Exception("Anahtarcı bilgisi alınamadı.Hata:" + resultAssembler.Result); } } if (entity.Contains("new_cityid") && entity["new_cityid"] != null) { cityId = (EntityReference)entity["new_cityid"]; } if (entity.Contains("new_townid") && entity["new_townid"] != null) { townId = (EntityReference)entity["new_townid"]; } if (entity.Contains("new_firstname") && entity["new_firstname"] != null) { customerFirstName = entity["new_firstname"].ToString(); } if (entity.Contains("new_lastname") && entity["new_lastname"] != null) { customerLastName = entity["new_lastname"].ToString(); } if (entity.Contains("new_mobilephone") && entity["new_mobilephone"] != null) { customerMobilePhone = entity["new_mobilephone"].ToString(); } if (!string.IsNullOrWhiteSpace(customerFirstName) && !string.IsNullOrWhiteSpace(customerLastName)) { customerFullName = customerFirstName + " " + customerLastName; } if (assemblerInfo != null && !string.IsNullOrWhiteSpace(assemblerInfo.FirstName) && !string.IsNullOrWhiteSpace(assemblerInfo.LastName)) { assemblerFullName = assemblerInfo.FirstName + " " + assemblerInfo.LastName; } #endregion #region | CREATE SMSs | if (!string.IsNullOrWhiteSpace(customerMobilePhone) && !string.IsNullOrWhiteSpace(customerFirstName) && !string.IsNullOrWhiteSpace(customerLastName) && assemblerInfo != null) { string customerSmsText = @"Sayın {0}, www.kalekilitesatis.com.tr sitemizden yaptığınız alışveriş için teşekkür ederiz. Montaj için anahtarcı bilgileri: {1}, Tel: {2}"; Entity ent = new Entity("new_sms"); ent["new_message"] = string.Format(customerSmsText, customerFullName, assemblerFullName, assemblerInfo.MobilePhoneNumber); ent["new_phonenumber"] = customerMobilePhone; ent["new_name"] = customerFirstName + " " + customerLastName + "|Montaj Talebi Mesajı"; service.Create(ent); } if (!string.IsNullOrWhiteSpace(assemblerInfo.MobilePhoneNumber) && !string.IsNullOrWhiteSpace(customerFirstName) && !string.IsNullOrWhiteSpace(customerLastName) && assemblerInfo != null && userId != null) { string customerSmsText = @"Sayın {0}, www.kalekilitesatis.com.tr sitemizden satışı yapılan ürünün montajı için müşteri bilgileri: {1} Tel: {2} şeklindedir. Müşterimizle irtibata geçmenizi rica ederiz."; Entity ent = new Entity("new_sms"); ent["new_message"] = string.Format(customerSmsText, assemblerFullName, customerFullName, customerMobilePhone); ent["new_phonenumber"] = assemblerInfo.MobilePhoneNumber; ent["new_name"] = customerFirstName + " " + customerLastName + "|Montaj Talebi Mesajı"; ent["new_userid"] = userId; service.Create(ent); } #endregion #region | CREATE NPS Survey | Entity entSurvey = new Entity("new_npssurvey"); entSurvey["new_name"] = customerFullName + "|" + DateTime.Now.ToString("dd.MM.yyyy HH:mm"); entSurvey["new_asseblyrequestid"] = entity.ToEntityReference(); service.Create(entSurvey); #endregion } catch (Exception ex) { //LOG throw new InvalidPluginExecutionException(ex.Message + "->>>" + ex.StackTrace); } finally { if (sda != null) { sda.closeConnection(); } } }