Example #1
0
        public static MsCrmResult UpdateSendSmsRecord(SendSmsRecord rec, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                Entity ent = new Entity("new_sentsms");
                ent["new_sentsmsid"]  = rec.Id;
                ent["new_issent"]     = rec.IsSent;
                ent["new_mesajid"]    = rec.MessageId;
                ent["new_resultcode"] = rec.ResultCode;
                ent["statuscode"]     = new OptionSetValue(rec.StatusCode);//işlendi
                ent["new_errortext"]  = rec.Error;

                service.Update(ent);

                returnValue.Success = true;
                returnValue.Result  = "Güncellendi...";
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return(returnValue);
        }
Example #2
0
        public static MsCrmResult CreateOrUpdateSendSmsRecord(SendSmsRecord rec, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                Entity ent = new Entity("new_sentsms");
                ent["new_name"] = rec.Name;

                if (rec.Id != null && rec.Id != Guid.Empty)
                {
                    ent["new_sentsmsid"] = rec.Id;
                }

                ent["new_issent"] = rec.IsSent;

                if (!string.IsNullOrEmpty(rec.MessageId))
                {
                    ent["new_mesajid"] = rec.MessageId;
                }

                if (!string.IsNullOrEmpty(rec.ResultCode))
                {
                    ent["new_resultcode"] = rec.ResultCode;
                }

                if (rec.StatusCode != null && rec.StatusCode != 0)
                {
                    ent["statuscode"] = new OptionSetValue(rec.StatusCode);
                }

                ent["new_errortext"] = rec.Error;

                if (rec.Contact != null)
                {
                    ent["new_contactid"] = rec.Contact;
                }
                ent["new_phonenumber"] = rec.PhoneNumber;

                if (rec.SmsConfiguration != null)
                {
                    ent["new_smsconfigurationid"] = new EntityReference("new_smsconfiguration", rec.SmsConfiguration.Id);
                }

                ent["new_prefferedsenddate"] = rec.PrefferedSendDate;
                ent["new_portalid"]          = rec.Portal;
                ent["new_content"]           = rec.Content;

                if (rec.Id == null || rec.Id == Guid.Empty)
                {
                    returnValue.CrmId = service.Create(ent);
                }
                else
                {
                    returnValue.CrmId = rec.Id;
                    service.Update(ent);
                }

                returnValue.Success = true;
                returnValue.Result  = "SMS kaydı oluşturuldu...";
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return(returnValue);
        }
Example #3
0
        public static MsCrmResultObject GetSendSsmsRecordInfo(Guid sendSmsId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |

                string sqlQuery = @"DECLARE @now DATETIME
                                SET @now=GETUTCDATE()

                                SELECT
	                                s.new_sentsmsId AS Id
	                                ,s.new_name AS Name
	                                ,s.statuscode AS StatusCode
	                                ,s.new_contactId AS ContactId
	                                ,s.new_contactIdName AS ContactIdName
	                                ,s.new_content AS Content
	                                ,s.new_errortext AS ErrorText
	                                ,s.new_issent AS IsSent
	                                ,s.new_MesajId AS MessageId
	                                ,s.new_phonenumber AS PhoneNumber
	                                ,s.new_prefferedsenddate AS PrefferedSendDate
	                                ,s.new_resultcode AS ResultCode
	                                ,s.new_smsconfigurationId AS SmsConfigurationId
	                                ,s.new_smsconfigurationIdName AS SmsConfigurationIdName
                                FROM
	                                new_sentsms AS s (NOLOCK)
                                WHERE
	                                s.new_sentsmsId='{0}'"    ;

                #endregion

                DataTable dt = sda.getDataTable(string.Format(sqlQuery, sendSmsId));

                if (dt.Rows.Count > 0)
                {
                    SendSmsRecord sendRec = new SendSmsRecord();

                    sendRec.Id         = (Guid)dt.Rows[0]["Id"];
                    sendRec.Name       = dt.Rows[0]["Name"].ToString();
                    sendRec.StatusCode = (int)dt.Rows[0]["StatusCode"];


                    if (dt.Rows[0]["ContactId"] != DBNull.Value)
                    {
                        EntityReference er = new EntityReference()
                        {
                            Id          = (Guid)dt.Rows[0]["ContactId"],
                            Name        = dt.Rows[0]["ContactIdName"].ToString(),
                            LogicalName = "contact"
                        };

                        sendRec.Contact = er;
                    }

                    sendRec.Content           = dt.Rows[0]["Content"].ToString();
                    sendRec.IsSent            = (bool)dt.Rows[0]["IsSent"];
                    sendRec.PhoneNumber       = dt.Rows[0]["PhoneNumber"].ToString();
                    sendRec.PrefferedSendDate = (DateTime)dt.Rows[0]["PrefferedSendDate"];
                    sendRec.ResultCode        = dt.Rows[0]["ResultCode"].ToString();

                    if (dt.Rows[0]["SmsConfigurationId"] != DBNull.Value)
                    {
                        //EntityReference er = new EntityReference()
                        //{
                        //    Id = (Guid)dt.Rows[0]["SmsConfigurationId"],
                        //    Name = dt.Rows[0]["SmsConfigurationId"].ToString(),
                        //    LogicalName = "new_smsconfiguration"
                        //};

                        //sendRec.SmsConfiguration = er;

                        MsCrmResultObject resultConf = SMSHelper.GetSmsConfigurationInfo((Guid)dt.Rows[0]["SmsConfigurationId"], sda);

                        if (resultConf.Success)
                        {
                            sendRec.SmsConfiguration = (SmsConfiguration)resultConf.ReturnObject;
                        }
                    }

                    returnValue.ReturnObject = sendRec;
                    returnValue.Success      = true;
                    returnValue.Result       = "Sms gönderme kaydı bilgisi çekildi.";
                }
                else
                {
                    returnValue.Result = "Sms Gönderim kaydı bilgisi çekilemedi.";
                }
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return(returnValue);
        }
Example #4
0
        SendSmsResult SendSms(string sessionId, SmsConfiguration smsConf, SendSmsRecord sendSms)
        {
            SendSmsResult returnValue = new SendSmsResult();

            smsService.smsservice smsApi = new smsService.smsservice();

            //string[] result = smsApi.SmsInsert_1_N("kalekulup", "cilingir123", null, null, new string[] { sendSms.PhoneNumber }, sendSms.Content);
            string[] result = smsApi.SmsInsert_1_N(smsConf.UserName, smsConf.Password, null, null, new string[] { sendSms.PhoneNumber }, sendSms.Content);

            //SendSMSRequest req = new SendSMSRequest();

            //req.DeleteDate = "";
            //req.GroupID = "0";
            //req.SendDate = "";

            //req.SessionID = sessionId;
            //req.Operator = (Operators)(int)smsConf.Operator;
            //req.Isunicode = Unicode.Yes;
            //req.Orginator = smsConf.Orginator;
            //req.ShortNumber = smsConf.ShortNumber;

            //MessageList mList = new MessageList();

            //List<Content> cList = new List<Content>();
            //List<GSM> gsmList = new List<GSM>();

            //Content cnt = new Content()
            //{
            //    Value = sendSms.Content
            //};

            //GSM gsm = new GSM()
            //{
            //    Value = sendSms.PhoneNumber
            //};

            //cList.Add(cnt);
            //gsmList.Add(gsm);

            //mList.ContentList = cList.ToArray();
            //mList.GSMList = gsmList.ToArray();

            //req.MessageList = mList;
            //SendMessageResponse resp = mService.SendSMS(req);

            returnValue.SendSmsCrmId = sendSms.Id;
            returnValue.StatusCode = result[0];

            //if (resp.Results != null)
            //    returnValue.MessageId = resp.Results[0].MessageID;

            return returnValue;
        }
Example #5
0
        public MsCrmResult SendPasswordSMS(string portalUserId, string portalId, string phoneNumber, string contactId)
        {
            Thread.Sleep(1000);
            MsCrmResult returnValue = new MsCrmResult();
            string token = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(portalUserId) && !string.IsNullOrEmpty(portalId) && !string.IsNullOrEmpty(phoneNumber))
                {
                    IOrganizationService service = MSCRM.GetOrgService(true);
                    mService = new MessageServices();

                    sda = new SqlDataAccess();
                    sda.openConnection(Globals.ConnectionString);

                    MsCrmResultObject resultSmsConf = SMSHelper.GetSmsConfigurationInfo(new Guid(Globals.SmsConfigurationDoluHayatId), sda);

                    if (!resultSmsConf.Success)
                    {
                        returnValue.Result = resultSmsConf.Result;
                        return returnValue;
                    }

                    SmsConfiguration smsConf = (SmsConfiguration)resultSmsConf.ReturnObject;

                    token = Guid.NewGuid().ToString().Replace("-", "");// resultSmsRecord.CrmId.ToString().Replace("-", "");

                    returnValue = SetPasswordSession(token, portalUserId, portalId, phoneNumber);

                    if (returnValue.Success)
                    {
                        SendSmsRecord smsRec = new SendSmsRecord()
                        {
                            Name = "Şifre Hatırlatma",
                            PhoneNumber = phoneNumber,
                            SmsConfiguration = smsConf,
                            PrefferedSendDate = DateTime.Now.AddHours(-2),
                            Portal = new EntityReference()
                            {
                                Id = new Guid(portalId),
                                LogicalName = "new_portal"
                            },
                            Contact = new EntityReference("contact", new Guid(contactId)),
                            Content = "Kale Anahtarcılar Kulübü Doğrulama Kodunuz: " + returnValue.Result,
                        };

                        //MsCrmResult resultSmsRecord = SMSHelper.CreateOrUpdateSendSmsRecord(smsRec, service);

                        //if (!resultSmsRecord.Success)
                        //{
                        //    returnValue = resultSmsRecord;
                        //    return returnValue;
                        //}

                        string sessionId = GetSession(smsConf);
                        SendSmsResult resultSms = SendSms(sessionId, smsConf, smsRec);

                        if (!resultSms.StatusCode.Contains("ERR"))
                        {
                            smsRec.IsSent = true;

                            smsRec.MessageId = resultSms.MessageId;
                            smsRec.ResultCode = resultSms.StatusCode;
                            smsRec.StatusCode = 100000000; //İşlendi

                            MsCrmResult resultSmsRecord = SMSHelper.CreateOrUpdateSendSmsRecord(smsRec, service);

                            returnValue = resultSmsRecord;
                            returnValue.Result = token;
                            returnValue.Success = true;
                        }
                        else
                        {
                            smsRec.Error = resultSms.StatusCode;
                            returnValue.Result = resultSms.StatusCode;
                        }
                    }
                }
                else
                {
                    returnValue.Success = false;
                    returnValue.Result = "M003";
                }

            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }

            return returnValue;
        }
Example #6
0
        public static MsCrmResult UpdateSendSmsRecord(SendSmsRecord rec, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                Entity ent = new Entity("new_sentsms");
                ent["new_sentsmsid"] = rec.Id;
                ent["new_issent"] = rec.IsSent;
                ent["new_mesajid"] = rec.MessageId;
                ent["new_resultcode"] = rec.ResultCode;
                ent["statuscode"] = new OptionSetValue(rec.StatusCode);//işlendi
                ent["new_errortext"] = rec.Error;

                service.Update(ent);

                returnValue.Success = true;
                returnValue.Result = "Güncellendi...";
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return returnValue;
        }
Example #7
0
        public static MsCrmResultObject GetSendSsmsRecordInfo(Guid sendSmsId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |

                string sqlQuery = @"DECLARE @now DATETIME
                                SET @now=GETUTCDATE()

                                SELECT
                                    s.new_sentsmsId AS Id
                                    ,s.new_name AS Name
                                    ,s.statuscode AS StatusCode
                                    ,s.new_contactId AS ContactId
                                    ,s.new_contactIdName AS ContactIdName
                                    ,s.new_content AS Content
                                    ,s.new_errortext AS ErrorText
                                    ,s.new_issent AS IsSent
                                    ,s.new_MesajId AS MessageId
                                    ,s.new_phonenumber AS PhoneNumber
                                    ,s.new_prefferedsenddate AS PrefferedSendDate
                                    ,s.new_resultcode AS ResultCode
                                    ,s.new_smsconfigurationId AS SmsConfigurationId
                                    ,s.new_smsconfigurationIdName AS SmsConfigurationIdName
                                FROM
                                    new_sentsms AS s (NOLOCK)
                                WHERE
                                    s.new_sentsmsId='{0}'";

                #endregion

                DataTable dt = sda.getDataTable(string.Format(sqlQuery, sendSmsId));

                if (dt.Rows.Count > 0)
                {
                    SendSmsRecord sendRec = new SendSmsRecord();

                    sendRec.Id = (Guid)dt.Rows[0]["Id"];
                    sendRec.Name = dt.Rows[0]["Name"].ToString();
                    sendRec.StatusCode = (int)dt.Rows[0]["StatusCode"];

                    if (dt.Rows[0]["ContactId"] != DBNull.Value)
                    {
                        EntityReference er = new EntityReference()
                        {
                            Id = (Guid)dt.Rows[0]["ContactId"],
                            Name = dt.Rows[0]["ContactIdName"].ToString(),
                            LogicalName = "contact"
                        };

                        sendRec.Contact = er;
                    }

                    sendRec.Content = dt.Rows[0]["Content"].ToString();
                    sendRec.IsSent = (bool)dt.Rows[0]["IsSent"];
                    sendRec.PhoneNumber = dt.Rows[0]["PhoneNumber"].ToString();
                    sendRec.PrefferedSendDate = (DateTime)dt.Rows[0]["PrefferedSendDate"];
                    sendRec.ResultCode = dt.Rows[0]["ResultCode"].ToString();

                    if (dt.Rows[0]["SmsConfigurationId"] != DBNull.Value)
                    {
                        //EntityReference er = new EntityReference()
                        //{
                        //    Id = (Guid)dt.Rows[0]["SmsConfigurationId"],
                        //    Name = dt.Rows[0]["SmsConfigurationId"].ToString(),
                        //    LogicalName = "new_smsconfiguration"
                        //};

                        //sendRec.SmsConfiguration = er;

                        MsCrmResultObject resultConf = SMSHelper.GetSmsConfigurationInfo((Guid)dt.Rows[0]["SmsConfigurationId"], sda);

                        if (resultConf.Success)
                        {
                            sendRec.SmsConfiguration = (SmsConfiguration)resultConf.ReturnObject;
                        }
                    }

                    returnValue.ReturnObject = sendRec;
                    returnValue.Success = true;
                    returnValue.Result = "Sms gönderme kaydı bilgisi çekildi.";
                }
                else
                {
                    returnValue.Result = "Sms Gönderim kaydı bilgisi çekilemedi.";
                }
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return returnValue;
        }
Example #8
0
        public static MsCrmResult CreateOrUpdateSendSmsRecord(SendSmsRecord rec, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                Entity ent = new Entity("new_sentsms");
                ent["new_name"] = rec.Name;

                if (rec.Id != null && rec.Id != Guid.Empty)
                {
                    ent["new_sentsmsid"] = rec.Id;
                }

                ent["new_issent"] = rec.IsSent;

                if (!string.IsNullOrEmpty(rec.MessageId))
                {
                    ent["new_mesajid"] = rec.MessageId;
                }

                if (!string.IsNullOrEmpty(rec.ResultCode))
                {
                    ent["new_resultcode"] = rec.ResultCode;
                }

                if (rec.StatusCode != null && rec.StatusCode != 0)
                {
                    ent["statuscode"] = new OptionSetValue(rec.StatusCode);
                }

                ent["new_errortext"] = rec.Error;

                if (rec.Contact != null)
                {
                    ent["new_contactid"] = rec.Contact;
                }
                ent["new_phonenumber"] = rec.PhoneNumber;

                if (rec.SmsConfiguration != null)
                {
                    ent["new_smsconfigurationid"] = new EntityReference("new_smsconfiguration", rec.SmsConfiguration.Id);
                }

                ent["new_prefferedsenddate"] = rec.PrefferedSendDate;
                ent["new_portalid"] = rec.Portal;
                ent["new_content"] = rec.Content;

                if (rec.Id == null || rec.Id == Guid.Empty)
                {
                    returnValue.CrmId = service.Create(ent);
                }
                else
                {
                    returnValue.CrmId = rec.Id;
                    service.Update(ent);
                }

                returnValue.Success = true;
                returnValue.Result = "SMS kaydı oluşturuldu...";
            }
            catch (Exception ex)
            {
                returnValue.Result = ex.Message;
            }

            return returnValue;
        }