public async Task LogException(string controllerName, string actionName, Exception exception)
        {
            var log = new ApiExceptionLog(controllerName, actionName, exception);

            _context.ApiExceptionsLog.Add(log);

            await _context.SaveChangesAsync();
        }
예제 #2
0
        public async Task <ActionResult <HomeInfoWithAlterByEmpEntity> > GetHomeInfoByEmp(string EmpID)
        {
            const string ProcedureID = "GetHomeInfoByEmp";

            bool bolInValid = false;
            HomeInfoWithAlterByEmpEntity HomeInfoWithAlterByEmpInfo = new HomeInfoWithAlterByEmpEntity();
            ActionResult  retResultWithStatus = null;
            string        sSQL     = string.Empty;
            HrisDbContext MyHrisDB = null;

            List <AlterbyEmpIDEntity> AlterbyEmpIDListInfo = null;
            List <WaitApproveEntity>  WaitApproveListInfo  = null;

            // 取得 首頁待填報資訊
            sSQL     = "EXEC [whs].[usp_GetAlterbyEmpID] {0}";
            MyHrisDB = new HrisDbContext();

            try
            {
                AlterbyEmpIDListInfo =
                    await MyHrisDB.AlterbyEmpIDEntitys
                    .FromSqlRaw(sSQL, EmpID)
                    .ToListAsync();
            }
            catch (Exception ex)
            {
                bolInValid          = true;
                retResultWithStatus = StatusCode(501, HomeInfoWithAlterByEmpInfo);


                var ael = new ApiExceptionLog
                {
                    ProcedureID = ProcedureID,
                    EmpID       = EmpID,
                    ProcedureStepDescription = "EXEC whs.[usp_GetAlterbyEmpID]"
                };
                await ApiExceptionLogHelper.AddLogSync(MyHrisDB, ex, ael);
            }



            // 抓取待批表單列表 =========================================================
            if (!bolInValid)
            {
                sSQL = "EXEC [whs].[usp_GetWaitApprove_WHS] {0}";
                try
                {
                    WaitApproveListInfo =
                        await MyHrisDB.WaitApproveEntitys
                        .FromSqlRaw(sSQL, EmpID)
                        .ToListAsync();
                }
                catch (Exception ex)
                {
                    bolInValid          = true;
                    retResultWithStatus = StatusCode(501, HomeInfoWithAlterByEmpInfo);

                    var ael = new ApiExceptionLog
                    {
                        ProcedureID = ProcedureID,
                        EmpID       = EmpID,
                        ProcedureStepDescription = "[whs].[usp_GetWaitApprove_WHS]"
                    };
                    await ApiExceptionLogHelper.AddLogSync(MyHrisDB, ex, ael);
                }
            }



            // 合併回傳資訊 ==============================================================
            if (!bolInValid)
            {
                HomeInfoWithAlterByEmpInfo = new HomeInfoWithAlterByEmpEntity()
                {
                    alterListInfo       = AlterbyEmpIDListInfo,
                    waitApproveListInfo = WaitApproveListInfo
                };
            }



            // 抓取員工首頁資訊 =========================================================
            if (!bolInValid)
            {
                sSQL = "EXEC [whs].[usp_GetHomeInfoByEmp] {0}";
                try
                {
                    IEnumerable <HomeInfoByEmpEntity> HomeInfoByEmpInfo =
                        MyHrisDB.HomeInfoByEmpEntitys
                        .FromSqlRaw(sSQL, EmpID)
                        .AsEnumerable();

                    HomeInfoWithAlterByEmpInfo.homeInfo = HomeInfoByEmpInfo?.FirstOrDefault();
                    retResultWithStatus = Ok(HomeInfoWithAlterByEmpInfo);
                }
                catch (Exception ex)
                {
                    bolInValid          = true;
                    retResultWithStatus = StatusCode(501, HomeInfoWithAlterByEmpInfo);

                    var ael = new ApiExceptionLog
                    {
                        ProcedureID = ProcedureID,
                        EmpID       = EmpID,
                        ProcedureStepDescription = "[whs].[usp_GetHomeInfoByEmp]"
                    };
                    await ApiExceptionLogHelper.AddLogSync(MyHrisDB, ex, ael);
                }
            }



            return(retResultWithStatus);
        }