public ContentResult SendNotification(NotificationModel model) { string connectionString = WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString(); const string notificationSender = "School Admin"; const string notificationCategory = "Test"; using (var con = new SqlConnection(connectionString)) { con.Open(); string query = "INSERT INTO [dbo].[tblNotification] ([PhoneNumber],[Sender],[Message],[Category]) VALUES('" + model.ToPhoneNumber + "', '" + notificationSender + "', '" + model.Message + "', '" + notificationCategory + "') "; var cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close(); } var smsResponseModel = SendSmsService.SendNotification(model.ToPhoneNumber, model.Message); AttendanceService.InsertSmsResponse(smsResponseModel); //return new JsonResult { Data = smsResponseModel, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; if (smsResponseModel.Status == "Success") { return(Content("Message Sent!")); } else { return(Content(smsResponseModel.Status)); } }
public ActionResult Index() { //TODO check if request.queryString.count > 1 in any scenario if (Request.QueryString.Count > 0) { //sample URL http://localhost:62206/ams?$99999&99&5780786&15112015114300,5780786&15112015184800 //sample URL http://localhost:62206/ams?$99999&OutMessages //Date format is ddmmyyyy string queryString = Request.QueryString[0].ToString(CultureInfo.InvariantCulture); if (queryString.Contains("OutMessages")) { string[] qsParameters = queryString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string orgId = RemoveSpecialChars(qsParameters[0]); DateTime outReportDate = DateTime.Today; var reportRequestModel = new ReportRequestModel { DtFrom = outReportDate.AddDays(-2), DtTo = outReportDate.AddDays(-2) }; var reportResponseModelWithContactsList = ReportService.GetAttendanceReportWithContacts(reportRequestModel); foreach (var reportResponseModelWithContacts in reportResponseModelWithContactsList) { var phoneNumber = reportResponseModelWithContacts.PhoneNumber; //Sending SMS using Bulk Service if (!String.IsNullOrEmpty(phoneNumber)) { var smsResponseModel = SendSmsService.SendSmsDailyReport(reportResponseModelWithContacts); AttendanceService.InsertSmsResponse(smsResponseModel); } } } else { string[] qsParameters = queryString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //TODO check max how many sub-requests allowed in one request - change to list if (qsParameters.Length >= 4) { string orgId = RemoveSpecialChars(qsParameters[0]); string machineId = qsParameters[1]; var requestModelList = new List <AttendanceRequestModel>(); for (int index = 2; index < qsParameters.Length; index++) { string rfId = qsParameters[index].Trim(); index++; string dtAttendance = RemoveSpecialChars(qsParameters[index]); DateTime dateTimeAttendance = DateTime.ParseExact(dtAttendance, "ddMMyyyyHHmmss", CultureInfo.InvariantCulture); var requestModel = new AttendanceRequestModel { OrgId = orgId, MachineId = machineId, RfId = rfId, DtAttendance = dateTimeAttendance }; requestModelList.Add(requestModel); } foreach (var requestModel in requestModelList) { /*if (!String.IsNullOrEmpty(orgId) && !String.IsNullOrEmpty(machineId) * && requestModel.RfId != null && !String.IsNullOrEmpty(requestModel.RfId) && requestModel.RfId.Length > 0 && requestModel.RfId.Length <= 16 * && requestModel.DtAttendance != null)//TODO check default value of datetime.parseexact*/ //Insert student attendance record and get the student details to send the SMS var attendanceResponseModel = AttendanceService.InsertOrUpdateAttendanceRecord(requestModel); //Sending SMS using Bulk Service if (!String.IsNullOrEmpty(attendanceResponseModel.PhoneNumber) && attendanceResponseModel.IsInTime) { var smsResponseModel = SendSmsService.SendSms(attendanceResponseModel, requestModel.DtAttendance); AttendanceService.InsertSmsResponse(smsResponseModel); } //query To get the value from table tblregistration //string selectquery = "Select * from tblregistration where UserId='" + rfId + "' "; // TODO ==> Identify In and Out Timestamps. as of now, morning 6 AM to 10 AM ==> IN Time , evening 3 to 6 ==> OUT Time // TODO ==> think of correct data model to maintain this data // TODO ==> fix RFID datatype in database.10 digits. // TODO ==> Make sure RFID is assigned to every student during registration. registration page of UI. if (requestModel.RfId != null) { //For Successfull Insertion Of Data Into database We are giving response To the device //return View(requestModel); Response.Write("$RFID=0#"); } } } } } return(View()); }
/// <summary> /// process an event for sendSms service. /// </summary> /// <param name="targetEvent"></param> /// <param name="t"></param> public override void ProcessEvent(EventDisplay targetEvent, TraceLog t) { t.CreateLog(null); t.CreateLog($"********************STARTED { TargetActionCode}********************************"); t.CreateLog("Start Of The Process For Event " + targetEvent.EventId + " And Service Number " + targetEvent.ServiceNumber + " - !!!! ServiceRequest() !!!!"); using (var EventClientWS = new SelcommWSsvc.SelcommWSAll.EventClient(Singtel.Helpers.Helpers.GetSelcommWsEndpointName())) using (var ContactClientWS = new SelcommWSsvc.SelcommWSAll.ContactClient(Singtel.Helpers.Helpers.GetSelcommWsEndpointName())) using (var ServiceClientWS = new SelcommWSsvc.SelcommWSAll.ServiceClient(Singtel.Helpers.Helpers.GetSelcommWsEndpointName())) { // Updating EventSchedule Status to R - START t.CreateLog("Updating Event Status to R- START - EventClientWS.EventScheduleUpdate()"); Singtel.Helpers.Helpers.updateEventStatus(SessionKey, targetEvent.EventId, "R", t, null); t.CreateLog("Updating Completed"); // Updating EventSchedule Status - END // Loading ServiceDisplay details of a current processing event t.CreateLog("Loading ServiceDisplay Details - ServiceClientWS.ServiceDisplay() For service id: " + targetEvent.ServiceId); var aService = ServiceClientWS.ServiceDisplay(this.ClientSessionWS.SessionKey, new SelcommWSsvc.SelcommWSAll.ServiceDisplay { Id = targetEvent.ServiceId }); if (aService != null) { t.CreateLog("ServiceDisplay Details loaded Successfully"); } else { t.CreateLog("ServiceDisplay Details not loaded"); } var ContactObj = ContactClientWS.Contact(ClientSessionWS.SessionKey, targetEvent.ContactCode, true, false, false, false); var businessUnitCode = ContactObj.CurrentBusinessUnit.Code; var eventNote = EventClientWS.EventNoteList(ClientSessionWS.SessionKey, targetEvent.EventId, false).FirstOrDefault(); try { SendSmsService newSMS = new SendSmsService(); sendSms newMSG = new sendSms(); List <string> address = new List <string>(); string aAddress = aService.ServiceNumber; //"tel:6596165414"; var FirstTwoDigitOfServiceNumber = Helpers.SmscHelper.GetFirstTwoDigitOfServiceNumber(aAddress); if (FirstTwoDigitOfServiceNumber != 65) { aAddress = "tel:65".Trim() + aAddress; } address.Add(aAddress); newMSG.addresses = address.ToArray(); newMSG.message = eventNote?.Text.ToString().Trim(); if (newMSG.message == null) { throw new Exception("Message should not be null. Event notes is null."); } newMSG.senderName = GetSystemConfigValue("SG_SMSC_FROM", "SG_SMSC_FROM_" + ContBusUnitCode); t.CreateLog($"Request sent from IOTB:{Utility.SerializeToJSON(newMSG)}"); sendSmsResponse newResponse = newSMS.sendSms(newMSG); t.CreateLog($"Response received{Utility.SerializeToJSON(newResponse)}"); } catch (Exception ex) { var sx = ex as System.Web.Services.Protocols.SoapException; if (sx != null) { t.CreateLog($"got SoapException. InnerText=\"{sx.Detail.InnerText}\""); t.CreateLog($"OuterXML=\"{sx.Detail.OuterXml}\""); } t.CreateLog("ex.ToString=" + ex.ToString()); //record the error and continue with next event t.CreateLog("----------------------------------------!! ERROR OCCURRED !!----------------------------------------"); string note = $"ERROR OCCURED. The provisioning action {TargetActionCode} stopped due to the reason: {ex.Message}"; t.CreateLog(note); SendEmailToWebSupport(note, t); Singtel.Helpers.Helpers.updateEventStatus(SessionKey, targetEvent.EventId, "F", t, note); } } }