コード例 #1
0
ファイル: LogAttribute.cs プロジェクト: SCDeveloper66/SC_Api
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var       userId    = JwtHelper.GetUserIdFromToken(HttpHelper.HttpContext);
            SystemLog systemLog = new SystemLog()
            {
                //IpAddress = HttpInfoUtility.GetCurrentIPAddress(),
                //Browser = HttpInfoUtility.GetCurrentBrowser(),
                //Date = DateTime.Now,
                //Device = HttpInfoUtility.GetCurrentDevice(),
                //Page = HttpInfoUtility.GetCurrentHost() + HttpInfoUtility.GetCurrentPage(),
                //Platform = HttpInfoUtility.GetCurrentPlatform(),
                //UserId = userId,
                //module = Enum.GetName(typeof(Method), _method),
                //ProgramName = _programName
            };

            Task.Run(() => _systemLogService.InsertSystemLogAsync(systemLog));

            base.OnActionExecuting(context);
        }
コード例 #2
0
        public async Task <TimeInOutViewModel> GetInoutRealtimeAsync(string language)
        {
            var data = new TimeInOutViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id    = userId,
                        time_type = "1",
                        lang      = language
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/TimeInOut/GetInoutRealtime",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter emp_id             = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter time_typeToday     = new SqlParameter("time_type", "1");
                    SqlParameter time_typeYesterday = new SqlParameter("time_type", "2");
                    SqlParameter lang = new SqlParameter("lang", language ?? "");

                    var spDataToday = context.SpMbEmpInoutRealtime.FromSqlRaw("sp_mb_emp_inout_realtime @emp_id, @time_type", emp_id, time_typeToday).ToList();
                    jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id    = userId,
                        time_type = "2",
                        lang      = language
                    });
                    systemLog = new SystemLog()
                    {
                        module   = "api/TimeInOut/GetInoutRealtime",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    var spDataYesterday = context.SpMbEmpInoutRealtime.FromSqlRaw("sp_mb_emp_inout_realtime @emp_id, @time_type", emp_id, time_typeYesterday).ToList();
                    data.content = new List <TimeInOutContentViewModel>();
                    TimeInOutContentViewModel today = new TimeInOutContentViewModel();
                    today.title  = "วันนี้";
                    today.childs = new List <TimeInOutContentchildsViewModel>();
                    foreach (var item in spDataToday)
                    {
                        TimeInOutContentchildsViewModel timeIn = new TimeInOutContentchildsViewModel();
                        timeIn.title  = item.title;
                        timeIn.detail = item.detail;
                        today.childs.Add(timeIn);
                    }
                    data.content.Add(today);
                    TimeInOutContentViewModel yesterday = new TimeInOutContentViewModel();
                    yesterday.title  = "วันที่ผ่านมา";
                    yesterday.childs = new List <TimeInOutContentchildsViewModel>();
                    foreach (var item in spDataYesterday)
                    {
                        TimeInOutContentchildsViewModel timeIn = new TimeInOutContentchildsViewModel();
                        timeIn.title  = item.title;
                        timeIn.detail = item.detail;
                        yesterday.childs.Add(timeIn);
                    }
                    data.content.Add(yesterday);

                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
コード例 #3
0
        public async Task <BenefitViewModel> GetOTSummaryAsync(string language, DateTime?start_date, DateTime?stop_date)
        {
            var data = new BenefitViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id       = userId,
                        lang         = language,
                        s_start_date = start_date,
                        s_stop_date  = stop_date
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/Benefit/GetOTSummary",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter emp_id       = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter s_start_date = new SqlParameter("s_start_date", start_date != null ? start_date.Value.ToString("dd/MM/yyyy") : "");
                    SqlParameter s_stop_date  = new SqlParameter("s_stop_date", stop_date != null ? stop_date.Value.ToString("dd/MM/yyyy") : "");
                    SqlParameter lang         = new SqlParameter("lang", language ?? "");

                    var spData_hours = context.SpMbEmpOTHoursResult.FromSqlRaw("sp_mb_emp_ot_hours @emp_id, @s_start_date, @s_stop_date, @lang", emp_id, s_start_date, s_stop_date, lang).ToList();
                    var spData_quota = context.SpMbEmpOTQuotaResult.FromSqlRaw("sp_mb_emp_ot_quota @emp_id, @s_start_date, @s_stop_date, @lang", emp_id, s_start_date, s_stop_date, lang).ToList();

                    data.quota_list = new List <Benefitline>();
                    data.hours_list = new List <Benefitline>();


                    double sumH = 0;
                    foreach (var item in spData_quota)
                    {
                        Benefitline news = new Benefitline();
                        news.line1 = item.ot_text;
                        news.hours = item.ot_hours;
                        data.quota_list.Add(news);
                        sumH += item.total_minute;
                    }
                    var HH      = sumH / 60;
                    var MM      = sumH % 60;
                    var totalQ  = HH.ToString().Split('.');
                    var totalQM = MM.ToString().Split('.');
                    data.quota = totalQ[0] + ":" + totalQM[0];

                    HH   = 0;
                    MM   = 0;
                    sumH = 0;
                    foreach (var item in spData_hours)
                    {
                        Benefitline news = new Benefitline();
                        news.line1 = item.ot_text;
                        news.hours = item.ot_hours;
                        data.hours_list.Add(news);
                        sumH += item.total_minute;
                    }
                    HH = sumH / 60;
                    MM = sumH % 60;
                    var totalH  = HH.ToString().Split('.');
                    var totalHM = MM.ToString().Split('.');
                    data.hours = totalH[0] + ":" + totalHM[0];

                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
コード例 #4
0
ファイル: UserService.cs プロジェクト: SCDeveloper66/SC_Api
        public async Task <EmpProfileViewModel> GetProfileAsync(string language)
        {
            var EmpProfile = new EmpProfileViewModel();

            EmpProfile.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id = userId,
                        lang   = language
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/User/GetProfile",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    var empDetail = context.EmpProfile.SingleOrDefault(a => a.EmpId.ToString() == userId);
                    if (empDetail != null)
                    {
                        SqlParameter emp_id = new SqlParameter("emp_id", userId ?? "");
                        SqlParameter lang   = new SqlParameter("lang", language ?? "");
                        var          spData = context.SpMbEmpProfile.FromSqlRaw("sp_mb_emp_profile @emp_id, @lang", emp_id, lang).ToList();

                        foreach (var item in spData)
                        {
                            EmpProfile.url_img      = item.url_img;
                            EmpProfile.name         = item.name ?? "-";
                            EmpProfile.lastname     = item.lastname ?? "-";
                            EmpProfile.id           = item.id;
                            EmpProfile.tel          = item.tel ?? "-";
                            EmpProfile.email        = item.email ?? "-";
                            EmpProfile.line         = item.line ?? "-";
                            EmpProfile.address      = item.address ?? "-";
                            EmpProfile.dist         = item.dist ?? "-";
                            EmpProfile.prov         = item.prov ?? "-";
                            EmpProfile.country      = item.country ?? "-";
                            EmpProfile.address_code = item.address_code ?? "-";
                            EmpProfile.outdoor_sts  = item.outdoor_sts;
                        }
                        EmpProfile.message.status = "1";
                        EmpProfile.message.msg    = "Success";
                    }
                    else
                    {
                        EmpProfile.message.status = "2";
                        EmpProfile.message.msg    = "Data not found";
                    }
                }
            }
            catch (Exception ex)
            {
                EmpProfile.message.status = "2";
                EmpProfile.message.msg    = ex.Message;
            }

            return(EmpProfile);
        }
コード例 #5
0
        public async Task <MeetingViewModel> GetMeetingAsync(string language)
        {
            var data = new MeetingViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id = userId,
                        lang   = language,
                        type   = "1",
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/Meeting/GetMeeting",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter emp_id    = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter typeToday = new SqlParameter("type", "1");
                    SqlParameter lang      = new SqlParameter("lang", language ?? "");
                    SqlParameter typeYes   = new SqlParameter("type", "2");

                    var spDataToday = context.SpMbMeeting.FromSqlRaw("sp_mb_meeting @emp_id, @type, @lang", emp_id, typeToday, lang).ToList();
                    jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id = userId,
                        lang   = language,
                        type   = "2",
                    });
                    systemLog = new SystemLog()
                    {
                        module   = "api/Meeting/GetMeeting",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    var spDataYes = context.SpMbMeeting.FromSqlRaw("sp_mb_meeting @emp_id, @type, @lang", emp_id, typeYes, lang).ToList();

                    data.content = new List <MeetingContentViewModel>();
                    MeetingContentViewModel viewModel = new MeetingContentViewModel();
                    viewModel.title  = "รายการนัดหมายปัจจุบัน";
                    viewModel.chlids = new List <MeetingChlidsViewModel>();

                    foreach (var item in spDataToday)
                    {
                        MeetingChlidsViewModel meetingChlids = new MeetingChlidsViewModel();
                        meetingChlids.title = item.title;
                        meetingChlids.line1 = item.line1;
                        meetingChlids.line2 = item.line2;
                        meetingChlids.line3 = item.line3;
                        meetingChlids.icon  = item.icon;
                        viewModel.chlids.Add(meetingChlids);
                    }
                    data.content.Add(viewModel);

                    viewModel        = new MeetingContentViewModel();
                    viewModel.title  = "รายการนัดหมายที่ผ่านมา";
                    viewModel.chlids = new List <MeetingChlidsViewModel>();

                    foreach (var item in spDataYes)
                    {
                        MeetingChlidsViewModel meetingChlids = new MeetingChlidsViewModel();
                        meetingChlids.title = item.title;
                        meetingChlids.line1 = item.line1;
                        meetingChlids.line2 = item.line2;
                        meetingChlids.line3 = item.line3;
                        meetingChlids.icon  = item.icon;
                        viewModel.chlids.Add(meetingChlids);
                    }
                    data.content.Add(viewModel);

                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
コード例 #6
0
        public async Task <TraningViewModel> GetTraningConditionAsync(string language)
        {
            var data = new TraningViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id   = userId,
                        v_year   = "",
                        v_prj_id = "",
                        v_lot_id = "",
                        lang     = language
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/Traning/GetTraningCondition",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter emp_id   = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter lang     = new SqlParameter("lang", language ?? "");
                    SqlParameter v_year   = new SqlParameter("v_year", "");
                    SqlParameter v_prj_id = new SqlParameter("v_prj_id", "");
                    SqlParameter v_lot_id = new SqlParameter("v_lot_id", "");

                    var spDataYear    = context.SpMbTrainingYear.FromSqlRaw("sp_mb_training_year @emp_id, @lang", emp_id, lang).ToList();
                    var spDataProject = context.SpMbTrainingProject.FromSqlRaw("sp_mb_training_project @emp_id, @v_year, @v_prj_id, @lang", emp_id, v_year, v_prj_id, lang).ToList();
                    var spDataLot     = context.SpMbTrainingLot.FromSqlRaw("sp_mb_training_lot @emp_id, @v_prj_id, @v_lot_id, @lang", emp_id, v_prj_id, v_lot_id, lang).ToList();

                    data.year    = new List <TraningYearViewModel>();
                    data.project = new List <TraningProjectViewModel>();
                    data.lot     = new List <TraningLotViewModel>();
                    foreach (var item in spDataYear)
                    {
                        TraningYearViewModel traning = new TraningYearViewModel();
                        traning.year_id   = item.year_id;
                        traning.year_text = item.year_id;
                        data.year.Add(traning);
                    }
                    foreach (var item in spDataProject)
                    {
                        TraningProjectViewModel traning = new TraningProjectViewModel();
                        traning.id      = item.id;
                        traning.name    = item.name;
                        traning.year_id = item.year_id;
                        data.project.Add(traning);
                    }
                    foreach (var item in spDataLot)
                    {
                        TraningLotViewModel traning = new TraningLotViewModel();
                        traning.id     = item.id;
                        traning.name   = item.name;
                        traning.prj_id = item.prj_id;
                        data.lot.Add(traning);
                    }

                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }