Esempio n. 1
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 <string> GetAttendanceList()
        {
            string dptId = "1";
            var    departmentUserListStr = await dtManager.GetDepartmentUserList(dptId);

            var departmentUserList = JsonConvert.DeserializeObject <DepartmentUserResponseModel>(departmentUserListStr);
            var userId             = departmentUserList.UserList.FirstOrDefault()?.UserId;
            var attendanceQuery    = new AttendanceRequestModel()
            {
                WorkDateFrom = DateTime.Now.AddDays(-7),
                WorkDateTo   = DateTime.Now
            };

            var result = await dtManager.GetAttendanceList(attendanceQuery);

            return(result);
        }
        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());
        }
        public Task <string> GetAttendanceList(AttendanceRequestModel query)
        {
            var url = _addressConfig.GetAttendanceListUrl;

            return(_client.UploadModel(url, query));
        }