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
            });
        }
示例#2
0
        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 async Task <IHttpActionResult> AddAttendance(AttendanceModel attendanceModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user     = UserManager.Users.Where(x => x.Email == User.Identity.Name).First();
            var employee = db.Employee.Where(y => y.Email == user.Email).First();
            var tag      = db.Tag.Where(x => x.SerialNumber == attendanceModel.SerialNumber).First();

            if (tag.TagContent != attendanceModel.NFCContentRead)
            {
                tag.TagContent = attendanceModel.NFCContentUploaded;
                await db.SaveChangesAsync();

                return(BadRequest("Tag content does not match."));
            }
            if (employee.Working != true)
            {
                tag.TagContent = attendanceModel.NFCContentUploaded;
                await db.SaveChangesAsync();

                return(BadRequest("Not allowed, employee not working."));
            }
            Attendance attendance = new Attendance
            {
                Employee           = employee.ID,
                Tag                = tag.ID,
                DateTime           = DateTime.Now,
                NFCContentRead     = attendanceModel.NFCContentRead,
                Confirmed          = true,
                NFCContentUploaded = attendanceModel.NFCContentUploaded
            };

            tag.TagContent = attendanceModel.NFCContentUploaded;
            db.Attendance.Add(attendance);
            await db.SaveChangesAsync();

            AttendanceResponseModel attendanceResponseModel = new AttendanceResponseModel
            {
                ID           = attendance.ID,
                TagInfo      = tag.Client1.Name + "/" + tag.Location1.Name + "/" + tag.TypeOfAttendance1.Name,
                EmployeeInfo = employee.Email
            };

            return(Ok(attendanceResponseModel));
        }