Exemplo n.º 1
0
    private void btnSendSMS_Click(object sender, EventArgs e)
    {
        string subject = (!string.IsNullOrEmpty(txtSubject.Text)) ? txtSubject.Text : "No subject";
        SmsHandler smsobj = new SmsHandler();
        SMSObjRepository smsobjRepo = new SMSObjRepository();
        AdministratorRepository ARepo = new AdministratorRepository();
        ObjLogin adm = (ObjLogin)Session["objLogin"];
        string SMSCode = Guid.NewGuid().ToString().ToLower();
       
        string listPhone = hdfPhoneNumbers.Value;
        if (string.IsNullOrEmpty(listPhone))
        {
            ShowErrorMessage("Please provide recipient to send");
            return;
        }

        char[] separator = new char[] { ',' };
        string[] phoneList = listPhone.Split(separator);
        bool flag = false;
        string PhoneNotExist = string.Empty;

        foreach (string phone in phoneList)
        {
            if (SRepo.CheckSalemenByPhoneNumber(phone))
            {
                smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.SalemenType, DateTime.Now, subject, 
                    txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                flag = true;
            }
            else
            {
                if (CRepo.IsExistedCustomerByPhone(phone))
                {
                    smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.CustomerType, DateTime.Now, subject, 
                        txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                    flag = true;
                }
                else
                {
                    if (ARepo.GetAdminByPhoneNumber(phone))
                    {
                        smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.AdminType, DateTime.Now, subject, txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                        flag = true;
                    }
                }
            }
            if (flag == false)
            {
                PhoneNotExist += phone + ", ";
            }
        }

        if (!string.IsNullOrEmpty(PhoneNotExist))
        {
            ShowErrorMessage(PhoneNotExist.Substring(0, PhoneNotExist.Length - 2) + " not found in database.");
        }
        else
        {
            ShowErrorMessage("Send success");
        }
    }