public static AttendanceResponseModel InsertOrUpdateAttendanceRecord(AttendanceRequestModel requestModel) { using (var con = new SqlConnection(ConnectionString)) { //Insert student attendance record and get the student details to send the SMS con.Open(); int rfidInt = int.Parse(requestModel.RfId); var cmd1 = new SqlCommand("InsertStudentAttendance", con) { CommandType = CommandType.StoredProcedure }; cmd1.Parameters.AddWithValue("@rfid", rfidInt); cmd1.Parameters.AddWithValue("@machineId", requestModel.MachineId); cmd1.Parameters.AddWithValue("@orgId", requestModel.OrgId); cmd1.Parameters.AddWithValue("@attendanceDateTime", requestModel.DtAttendance); cmd1.Parameters.Add("@phoneNumber", SqlDbType.Float); cmd1.Parameters["@phoneNumber"].Direction = ParameterDirection.Output; cmd1.Parameters.Add("@studentName", SqlDbType.VarChar, 765); cmd1.Parameters["@studentName"].Direction = ParameterDirection.Output; cmd1.Parameters.Add("@isInTime", SqlDbType.Bit); cmd1.Parameters["@isInTime"].Direction = ParameterDirection.Output; cmd1.ExecuteReader(); con.Close(); var attendanceResponseModel = new AttendanceResponseModel { PhoneNumber = cmd1.Parameters["@PhoneNumber"].Value.ToString(), StudentName = cmd1.Parameters["@studentName"].Value.ToString(), IsInTime = Convert.ToBoolean(cmd1.Parameters["@isInTime"].Value) }; return attendanceResponseModel; } }
public static SmsResponseModel SendSms(AttendanceResponseModel responseModel, DateTime dtAttendance) { string subMsg = responseModel.IsInTime ? " has entered the campus at " : " has left the campus at "; var msg = string.Format("{0}{1}{2}", responseModel.StudentName, subMsg, dtAttendance); /*string smsUrl = String.Format("{0}&mobileno={1}&msg={2}", //WebConfigurationManager.AppSettings["BulkSMSBaseUrl"], responseModel.PhoneNumber, msg);*/ string smsUrl = String.Format("{0}&from={1}&to={2}&msg={3}", //WebConfigurationManager.AppSettings["BulkSMSBaseUrl"],"EduKriti", responseModel.PhoneNumber, msg); WebConfigurationManager.AppSettings["BulkSMSBaseUrl"], "SCHOOL", "9063713741", msg); var client = new WebClient(); var response = client.DownloadString(smsUrl); var status = "Failure"; if (!string.IsNullOrEmpty(response) && response.IsNumeric()) { status = "Success"; } return new SmsResponseModel { Response = response, SmsUrl = smsUrl, Status = status }; }