Ejemplo n.º 1
0
 public ActionResult Rspv(Attendes attendes)
 {
     if (ModelState.IsValid)
     {
         Repository.AddAttendes(attendes);
         return(View("Thanks", attendes));
     }
     return(View());
 }
Ejemplo n.º 2
0
        public Result getAttendes(string startDate)
        {
            int    user   = 0;
            Result result = new Result();
            int    year   = DateTime.Now.AddDays(-1).Year;
            int    month  = DateTime.Now.AddDays(-1).Month;
            int    day    = DateTime.Now.AddDays(-1).Day;

            if (String.IsNullOrEmpty(startDate))
            {
                startDate = "" + year + "-" + month + "-" + day;
            }
            try
            {
                query = "select distinct n.Field12_50 as 'userCode', CAST(m.EventTime AS DATE) as 'date',"
                        + " (select top(1)EventTime from EventsEx  where PeripheralName like '%:In' and UserID = m.UserID and CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "') order by EventTime asc) as 'inTime',"
                        + " (select top(1)EventTime from EventsEx where PeripheralName like '%:Out' and UserID = m.UserID and CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "') order by EventTime desc) as 'outTime',"
                        + " (select top(1)PeripheralName from EventsEx where PeripheralName like '%:In' and UserID = m.UserID and CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "') order by EventTime asc) as 'inLocation',"
                        + " (select top(1)PeripheralName from EventsEx where PeripheralName like '%:Out' and UserID = m.UserID and CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "') order by EventTime desc) as 'outLocation'"
                        + " from EventsEx m inner"
                        + " join UsersEx n on m.UserID = n.UserID where CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "') and m.UserID in"
                        + " (select distinct e.UserID from EventsEx as e"
                        + " inner join UsersEx u on e.UserID = u.UserID where"
                        + " CAST(EventTime AS DATE) = CONVERT(date, '" + startDate + "')"
                        + " and e.PeripheralName like '%:Out' and u.Field12_50 is not null"
                        + " and e.UserID in (select distinct u.UserID from EventsEx as e"
                        + " inner join UsersEx u on e.UserID = u.UserID"
                        + " where CAST(EventTime AS DATE)= CONVERT(date, '" + startDate + "') and e.PeripheralName like '%:In'))";
                users       = oemClient.GetListOfOperators().UsersDictionary();
                net2Methods = oemClient.AuthenticateUser(0, password);
                List <Attendes> attendesList = new List <Attendes>();
                DataSet         userSet      = oemClient.QueryDb(query);
                DataTable       userTable    = userSet.Tables[0];
                int             size         = userTable.Rows.Count;
                var             options      = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 10
                };
                Parallel.For(0, size, options, i =>
                {
                    Attendes info    = new Attendes();
                    info.date        = startDate;
                    info.elployeeID  = userTable.Rows[i][0].ToString() ?? "";
                    info.inTime      = userTable.Rows[i][2].ToString();
                    info.inLocation  = userTable.Rows[i][4].ToString();
                    info.outTime     = userTable.Rows[i][3].ToString();
                    info.outLocation = userTable.Rows[i][5].ToString();
                    info.duration    = common.getDuration(info.inTime, info.outTime);
                    if (!info.duration.Contains('-'))
                    {
                        attendesList.Add(info);
                    }
                });
                result.status = true;
                result.List   = attendesList;
                return(result);
            }
            catch (Exception ex)
            {
                result.status  = false;
                result.message = ex.Message + " For user:" + user;
                return(result);
            }
        }