protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (GetLastContactGroupMapingId() == 0)
        {
            var contactGroupSheetMaping = new ContactGroupSheetMaping();
            contactGroupSheetMaping.ContactGroupId = Convert.ToInt32(ddlGroup.SelectedValue);
            contactGroupSheetMaping.SheetId = Convert.ToInt32(ddlSheet.SelectedValue);
            contactGroupSheetMaping.IsDelete = false;
            contactGroupSheetMaping.CreatedOn = DateTime.Now;
            _dbScheduler.ContactGroupSheetMapings.InsertOnSubmit(contactGroupSheetMaping);
            _dbScheduler.SubmitChanges();
            int id = GetLastContactGroupMapingId();
            var contacts = from contact in _dbScheduler.Contacts
                           where
                               (contact.ContactGroupId == Convert.ToInt32(ddlSheet.SelectedValue) &&
                                contact.IsDelete == false)
                           select contact;
            var messages = from sms in _dbScheduler.SmsTemplates
                           where sms.IsDelete == false && sms.SheetId == Convert.ToInt32(ddlSheet.SelectedValue)
                           select sms;
            var smsSchedules = new List<SmsSchedule>();
            foreach (var message in messages)
            {

                    smsSchedules.Add(new SmsSchedule()
                        {
                            IsDelete = false,
                            ContactId = Convert.ToInt32(ddlGroup.SelectedValue),
                            IsRecursive = 0,
                            SmsTemplateId = message.Id,
                            IsSent = false,
                            MapingId = id,
                            SentOn = message.SendingDate

                        });
                    for (int i = 0; i < message.NoOfTimes; i++)
                    {

                        if (message.SendingDate != null)
                            smsSchedules.Add(new SmsSchedule()
                                {
                                    IsDelete = false,
                                    ContactId = Convert.ToInt32(ddlSheet.SelectedValue),
                                    IsRecursive = 0,
                                    SmsTemplateId = message.Id,
                                    IsSent = false,
                                    MapingId = id,
                                    SentOn = message.SendingDate.Value.AddDays(Convert.ToDouble(message.RepeatAfter)),
                                });
                    }

            }
            _dbScheduler.SmsSchedules.InsertAllOnSubmit(smsSchedules);
            _dbScheduler.SubmitChanges();
        }
    }
 partial void UpdateContactGroupSheetMaping(ContactGroupSheetMaping instance);
 partial void DeleteContactGroupSheetMaping(ContactGroupSheetMaping instance);
 partial void InsertContactGroupSheetMaping(ContactGroupSheetMaping instance);