// Enable initialization with an instance of ApplicationUser: public SelectUserRolesViewModel(Employee user) : this() { UserName = user.UserName; var db = new HrisDbContext(); // Add all available roles to the list of EditorViewModels: var allRoles = db.Roles; foreach (var role in allRoles) { var rvm = new SelectRoleEditorViewModel(role); Roles.Add(rvm); } // Set the Selected property to true for those roles for // which the current user is a member: foreach (var userRole in user.Roles) { var checkUserRole = Roles.Find(r => r.RoleId == userRole.RoleId); checkUserRole.Selected = true; } }
public async Task <ActionResult <IEnumerable <WaitApproveEntity> > > GetWaitApprove_WHS(string EmpID) { List <WaitApproveEntity> WaitApproveListInfo = new List <WaitApproveEntity>(); // 檢查傳入參數 ========================================== EmpID = EmpID.Trim(); if (EmpID.Length != 6) { return(StatusCode(401, WaitApproveListInfo)); } // ======================================================================== string sSQL = "EXEC [whs].[usp_GetWaitApprove_WHS] {0}"; var MyHrisDB = new HrisDbContext(); try { WaitApproveListInfo = await MyHrisDB.WaitApproveEntitys .FromSqlRaw(sSQL, EmpID) .ToListAsync(); } catch (Exception ex) { return(StatusCode(501, WaitApproveListInfo)); } return(Ok(WaitApproveListInfo)); }
public ActionResult UserRoles(string id) { var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == id); var model = new SelectUserRolesViewModel(user); return(View(model)); }
public async Task <ActionResult <List <WaitApproveDayStaticEntity> > > GetWaitApproveDayStaticByDateRange(string EmpID, string StartDateNo, string EndDateNo) { bool bolInValid = false; List <WaitApproveDayStaticEntity> WaitApproveDayStaticListInfo = new List <WaitApproveDayStaticEntity>(); ActionResult retResultWithStatusCode = null; DateTime dtStartDate = default(DateTime); DateTime dtEndDate = default(DateTime); // 傳入參數設定與檢查 ========================================================== string StartDate = StartDateNo.Substring(0, 4) + "/" + StartDateNo.Substring(4, 2) + "/" + StartDateNo.Substring(6, 2); string EndDate = EndDateNo.Substring(0, 4) + "/" + EndDateNo.Substring(4, 2) + "/" + EndDateNo.Substring(6, 2); if (DateTime.TryParse(StartDate, out dtStartDate) == false) { bolInValid = true; retResultWithStatusCode = StatusCode(401, WaitApproveDayStaticListInfo); } if (DateTime.TryParse(EndDate, out dtEndDate) == false) { bolInValid = true; retResultWithStatusCode = StatusCode(401, WaitApproveDayStaticListInfo); } // 取得資料 ====================================================================== if (!bolInValid) { string sSQL = "EXEC [whs].[usp_GetWaitApproveDayStatic] {0}, {1}, {2}"; var MyHrisDB = new HrisDbContext(); try { WaitApproveDayStaticListInfo = await MyHrisDB.WaitApproveDayStaticEntitys .FromSqlRaw(sSQL, EmpID, dtStartDate, dtEndDate) .ToListAsync(); retResultWithStatusCode = Ok(WaitApproveDayStaticListInfo); } catch (Exception ex) { bolInValid = true; retResultWithStatusCode = StatusCode(501, WaitApproveDayStaticListInfo); } } return(retResultWithStatusCode); }
public ActionResult DeleteConfirmed(string id) { var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == id); db.Users.Remove(user); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(string id, ManageMessageId?message = null) { var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == id); var model = new EditUserViewModel(user); ViewBag.MessageId = message; return(View(model)); }
public List <EmpWorkingJobCodeToTreeEntity> GetWorkingDateJobCodebyEmpID(string EmpID, string WorkingDateNo) { List <EmpWorkingJobCodeToTreeEntity> lstEmpWorkingJobCodeToTreeInfo = new List <EmpWorkingJobCodeToTreeEntity>(); // 檢查傳入參數======================================================================== string WorkDate = WorkingDateNo.Substring(0, 4) + "/" + WorkingDateNo.Substring(4, 2) + "/" + WorkingDateNo.Substring(6, 2); if (DateTime.TryParse(WorkDate, out DateTime dteWorkDate) == false) { return(null); } // 取得資料 ====================================================================== // 取得原始資料 string sSQL = "EXEC [whs].[usp_GetWorkingDateJobCodebyEmpID] {0}, {1}"; var MyHrisDB = new HrisDbContext(); var WorkingDateJobCodebyEmpIDList = MyHrisDB.WorkingDateJobCodebyEmpIDEntitys.FromSqlRaw(sSQL, EmpID, WorkDate).ToList(); // 取得 TypeCode list var EmpWorkingTypeCodeList = WorkingDateJobCodebyEmpIDList.Select(p => new { p.TypeCode, p.TypeName }).Distinct(); // 巡覽所有的TypeCode foreach (var currentTypeInfo in EmpWorkingTypeCodeList) { EmpWorkingJobCodeToTreeEntity currentJobCodeTree = new EmpWorkingJobCodeToTreeEntity() { TypeCode = currentTypeInfo.TypeCode, TypeName = currentTypeInfo.TypeName }; // 取得該TypeCode下的JobCode list List <JobCodeEntity> currentJobCodeInfoEnum = (from currentWorkingDateJobCodebyEmpID in WorkingDateJobCodebyEmpIDList where currentWorkingDateJobCodebyEmpID.TypeCode == currentJobCodeTree.TypeCode select new JobCodeEntity { JobCode = currentWorkingDateJobCodebyEmpID.JobCode, JobName = currentWorkingDateJobCodebyEmpID.JobName }).ToList(); currentJobCodeTree.DetailList = currentJobCodeInfoEnum; lstEmpWorkingJobCodeToTreeInfo.Add(currentJobCodeTree); } return(lstEmpWorkingJobCodeToTreeInfo); }
public IActionResult SignBatchApprovalByDateRange([FromBody] BatchSignApprovalByDateRangeEntity BatchSignApprovalByDateRangeInfo) { bool bolInValid = false; string SignID = BatchSignApprovalByDateRangeInfo.SignID.Trim(); string IsApproval = BatchSignApprovalByDateRangeInfo.IsApproval.Trim(); if (DateTime.TryParse(BatchSignApprovalByDateRangeInfo.StartDate, out DateTime dtStartDate) == false) { bolInValid = true; } if (DateTime.TryParse(BatchSignApprovalByDateRangeInfo.EndDate, out DateTime dtEndDate) == false) { bolInValid = true; } int WaitApproveItemCount = BatchSignApprovalByDateRangeInfo.WaitApproveItemCount; if (bolInValid == true || IsApproval != "1") { return(StatusCode(401)); } // ===================================================== string[] param = new[] { SignID, dtStartDate.ToString("yyyy/MM/dd"), dtEndDate.ToString("yyyy/MM/dd"), WaitApproveItemCount.ToString() }; string sSQL = @"EXEC [whs].[usp_UpdatedProcessStatusBySignBatchWeek] @SignID = {0}, @startDate = {1}, @endDate = {2}, @SingRemark = '單週批核簽准', @UpdatedBy = NULL"; var MyHrisDB = new HrisDbContext(); try { MyHrisDB.Database.ExecuteSqlRaw(sSQL, param); } catch (Exception ex) { return(StatusCode(501)); } return(Ok()); }
public ActionResult Delete(string id = null) { var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == id); var model = new EditUserViewModel(user); if (user == null) { return(HttpNotFound()); } return(View(model)); }
public ActionResult Index() { var db = new HrisDbContext(); var users = db.Users; var model = new List <EditUserViewModel>(); foreach (var user in users) { var u = new EditUserViewModel(user); model.Add(u); } return(View(model)); }
public ActionResult <InsertWorkingHoursDetailReturnEntity> InsertWorkingHoursDetail([FromBody] InsertWorkingHoursDetailEntity empWorkingHoursDetailEntity) { InsertWorkingHoursDetailReturnEntity retInsertWorkingHoursDetailReturnInfo = null; string RowUnid = empWorkingHoursDetailEntity.RowUnid; string TypeCode = empWorkingHoursDetailEntity.TypeCode; string JobCode = empWorkingHoursDetailEntity.JobCode; decimal WorkingHours = empWorkingHoursDetailEntity.WorkingHours; string Note = empWorkingHoursDetailEntity.Note; string CreatedBy = empWorkingHoursDetailEntity.CreatedBy; string[] param = new[] { RowUnid, TypeCode, JobCode, WorkingHours.ToString(), Note, CreatedBy }; string sSQL = @"EXEC [whs].[usp_InsertWorkingHoursDetail] @RowUnid = {0}, @TypeCode = {1}, @JobCode = {2}, @WorkingHours = {3}, @Note = {4}, @CreatedBy = {5}"; var MyHrisDB = new HrisDbContext(); try { var returnMessageList = MyHrisDB.InsertWorkingHoursDetailReturnEntitys.FromSqlRaw(sSQL, param).ToList(); if (returnMessageList != null && returnMessageList.Count > 0) { retInsertWorkingHoursDetailReturnInfo = returnMessageList[0]; } } catch { //return internalser (retInsertWorkingHoursDetailReturnInfo); return(StatusCode(501)); } return(Ok(retInsertWorkingHoursDetailReturnInfo)); }
public ActionResult <UpdateWorkingHoursDetailReturnEntity> UpdateWorkingHoursDetail([FromBody] UpdateWorkingHoursDetailEntity empWorkingHoursDetailEntity) { UpdateWorkingHoursDetailReturnEntity retUpdateWorkingHoursDetailReturnInfo = null; string RowUnid = empWorkingHoursDetailEntity.RowUnid; string TypeCode = empWorkingHoursDetailEntity.TypeCode; string JobCode = empWorkingHoursDetailEntity.JobCode; decimal WorkingHours = empWorkingHoursDetailEntity.WorkingHours; string Note = empWorkingHoursDetailEntity.Note; string CreatedBy = empWorkingHoursDetailEntity.CreatedBy; string[] param = new[] { RowUnid, TypeCode, JobCode, WorkingHours.ToString(), Note, CreatedBy }; string sSQL = @"EXEC [whs].[usp_UpdateWorkingHoursDetail] @RowUnid = {0}, @TypeCode = {1}, @JobCode = {2}, @WorkingHours = {3}, @Note = {4}, @CreatedBy = {5}"; var MyHrisDB = new HrisDbContext(); try { var varUpdateWorkingHoursDetailReturn = MyHrisDB.UpdateWorkingHoursDetailReturnEntitys.FromSqlRaw(sSQL, param) .ToList(); if (varUpdateWorkingHoursDetailReturn != null && varUpdateWorkingHoursDetailReturn.Count > 0) { retUpdateWorkingHoursDetailReturnInfo = varUpdateWorkingHoursDetailReturn[0]; } } catch { return(StatusCode(501, retUpdateWorkingHoursDetailReturnInfo)); } return(Ok(retUpdateWorkingHoursDetailReturnInfo)); }
public IActionResult UpdatedProcessStatusBySign([FromBody] UpdatedProcessStatusBySignEntity UpdatedProcessStatusInfo) { string FlowID = UpdatedProcessStatusInfo.FlowID.Trim(); string SignID = UpdatedProcessStatusInfo.SignID.Trim(); string SingRemark = UpdatedProcessStatusInfo.SingRemark.Trim(); string IsFinish = UpdatedProcessStatusInfo.IsFinish.Trim(); string UpdatedBy = UpdatedProcessStatusInfo.UpdatedBy.Trim(); if (FlowID == string.Empty || SignID == string.Empty || IsFinish == string.Empty || UpdatedBy == string.Empty) { return(StatusCode(401)); } string[] param = new[] { FlowID, SignID, SingRemark, IsFinish, UpdatedBy }; string sSQL = @"EXEC [whs].[usp_UpdatedProcessStatusBySign] @FlowID = {0}, @SignID = {1}, @SingRemark = {2}, @IsFinish = {3}, @UpdatedBy = {4}"; var MyHrisDB = new HrisDbContext(); try { MyHrisDB.Database.ExecuteSqlRaw(sSQL, param); } catch (Exception ex) { return(StatusCode(501)); } return(Ok()); }
public async Task <ActionResult> Edit(EditUserViewModel model) { if (ModelState.IsValid) { var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == model.UserName); user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; db.Entry(user).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
/// <summary> /// 取得RowUnid /// </summary> /// <param name="EmpID">員工代碼</param> /// <param name="WorkingDate">工作日</param> /// <remarks> /// 傳入EmpID, WorkingDate,查詢並轉換為單日填報RowUnid代碼 /// </remarks> /// <returns></returns> protected string GetWorkingHoursRowUnidByWorkingDate(string EmpID, DateTime WorkingDate) { string RowUnid = null; // 查詢 [whs].[WorkingHours] var MyHrisDB = new HrisDbContext(); var WorkingHoursQuerable = MyHrisDB.TB_WorkingHours .Where(b => b.EmpID == EmpID && b.WorkingDate == WorkingDate); if (WorkingHoursQuerable != null && WorkingHoursQuerable.Count() > 0) { WorkingHoursEntity WorkingHoursInfo = WorkingHoursQuerable.FirstOrDefault(); RowUnid = WorkingHoursInfo?.RowUnid; } return(RowUnid); }
public ActionResult UserRoles(SelectUserRolesViewModel model) { if (ModelState.IsValid) { var idManager = new IdentityManager(); var db = new HrisDbContext(); var user = db.Users.First(u => u.UserName == model.UserName); idManager.ClearUserRoles(user.Id); foreach (var role in model.Roles) { if (role.Selected) { idManager.AddUserToRole(user.Id, role.RoleName); } } return(RedirectToAction("index")); } return(View()); }
public IActionResult DeleteWorkingHoursDetail([FromBody] DeleteWorkingHoursDetailHandleEntity empWorkingHoursDetailHandleInfo) { // ======================================================= string RowUnid = empWorkingHoursDetailHandleInfo.RowUnid.Trim(); string TypeCode = empWorkingHoursDetailHandleInfo.TypeCode.Trim(); string JobCode = empWorkingHoursDetailHandleInfo.JobCode.Trim(); string[] arySqlParam = new[] { RowUnid, TypeCode, JobCode }; if (RowUnid == string.Empty || TypeCode == string.Empty || JobCode == string.Empty) { return(StatusCode(401)); } // =================================================================== string sSQL = @"EXEC [whs].[usp_DeleteWorkingHoursDetail] @RowUnid = {0}, @TypeCode = {1}, @JobCode = {2}"; var MyHrisDB = new HrisDbContext(); try { MyHrisDB.Database.ExecuteSqlRaw(sSQL, arySqlParam); } catch { return(StatusCode(501)); } return(Ok()); }
public ActionResult <ApplicationDetailEntity> GetApplicationDetail(string FlowID) { // =========================================== ApplicationDetailEntity retApplicationDetailInfo = new ApplicationDetailEntity(); List <WorkdateListEntity> retWorkdateList = new List <WorkdateListEntity>(); // ============================================ var MyHrisDB = new HrisDbContext(); // 查詢ProcessStatus ==================================================== // 申請案件基本資料 ProcessStatusEntity ProcessStatusInfo = MyHrisDB.TB_ProcessStatusEntitys .Where(b => b.FlowID == FlowID && b.IsDeleted == "0").FirstOrDefault(); if (ProcessStatusInfo == null) { return(NotFound(retApplicationDetailInfo)); } string EmpID = ProcessStatusInfo.ApplyID; string EmpName = MyHrisDB.TB_Employees .Where(e => e.EmpID == EmpID).Select(e => e.EmpName.Trim()).FirstOrDefault(); retApplicationDetailInfo.Home = new ApplicationDetailHomeEntity() { EmpName = EmpName }; // 查詢ProcessStatusDetail ==================================================== // 申請案件明細資料 List <ProcessStatusDetailEntity> ProcessStatusDetailListInfo = MyHrisDB.TB_ProcessStatusDetailEntitys .Where(p => p.FlowID == FlowID).ToList(); foreach (string currentRowUnid in ProcessStatusDetailListInfo .Select(p => p.RowUnid.Trim())) { WorkingHoursEntity WorkingHoursEntityInfo = MyHrisDB.TB_WorkingHours .Where(w => w.RowUnid == currentRowUnid && w.IsDelete == "0") .FirstOrDefault(); if (WorkingHoursEntityInfo == null) { return(NotFound(retApplicationDetailInfo)); } List <WorkingHoursDetailWithJobNameEntity> WorkingHoursDetailWithJobNameListInfo = (from currentvwWorkingHoursDetailInfo in MyHrisDB.VW_vwWorkingHoursDetailEntitys where currentvwWorkingHoursDetailInfo.RowUnid == currentRowUnid select new WorkingHoursDetailWithJobNameEntity { TypeCode = currentvwWorkingHoursDetailInfo.TypeCode, JobCode = currentvwWorkingHoursDetailInfo.JobCode, JobName = currentvwWorkingHoursDetailInfo.JobName, WorkingHours = currentvwWorkingHoursDetailInfo.WorkingHours, Note = currentvwWorkingHoursDetailInfo.Note }).ToList(); WorkdateListEntity WorkdateListInfo = new WorkdateListEntity(); WorkdateListInfo.RowUnid = WorkingHoursEntityInfo.RowUnid; WorkdateListInfo.WorkingDate = WorkingHoursEntityInfo.WorkingDate.ToString("yyyy-MM-dd"); WorkdateListInfo.WorkingHourDetailList = WorkingHoursDetailWithJobNameListInfo; retWorkdateList.Add(WorkdateListInfo); } retApplicationDetailInfo.WorkdateList = retWorkdateList; return(Ok(retApplicationDetailInfo)); }
public async Task <ActionResult <WaitApproveStaticAndDetailEntity> > GetWaitApproveDetailByDateRange(string EmpID, string StartDateNo, string EndDateNo) { bool bolInValid = false; WaitApproveStaticAndDetailEntity WaitApproveStaticAndDetailInfo = new WaitApproveStaticAndDetailEntity(); List <WaitApproveDetailEntity> WaitApproveDetailListInfo = null; ActionResult retResultWithStatus = null; DateTime dtStartDate = default(DateTime); DateTime dtEndDate = default(DateTime); // 待批案件筆數 int WaitApproveDetailItemCount = 0; string sSQL = string.Empty; HrisDbContext MyHrisDB = new HrisDbContext(); // 傳入參數設定與檢查 ========================================================== string StartDate = StartDateNo.Substring(0, 4) + "/" + StartDateNo.Substring(4, 2) + "/" + StartDateNo.Substring(6, 2); string EndDate = EndDateNo.Substring(0, 4) + "/" + EndDateNo.Substring(4, 2) + "/" + EndDateNo.Substring(6, 2); if (DateTime.TryParse(StartDate, out dtStartDate) == false) { bolInValid = true; retResultWithStatus = StatusCode(401, WaitApproveStaticAndDetailInfo); } if (DateTime.TryParse(EndDate, out dtEndDate) == false) { bolInValid = true; retResultWithStatus = StatusCode(401, WaitApproveStaticAndDetailInfo); } // 取得資料 ====================================================================== if (!bolInValid) { sSQL = "EXEC [whs].[usp_GetWaitApproveDetail] {0}, {1}, {2}"; MyHrisDB = new HrisDbContext(); try { WaitApproveDetailListInfo = await MyHrisDB.WaitApproveDetailEntitys .FromSqlRaw(sSQL, EmpID, dtStartDate, dtEndDate) .ToListAsync(); } catch (Exception ex) { bolInValid = true; retResultWithStatus = StatusCode(501, WaitApproveStaticAndDetailInfo); } } // 回傳資料 ============================================================== if (bolInValid) { return(retResultWithStatus); } else { if (WaitApproveDetailListInfo != null) { WaitApproveDetailItemCount = WaitApproveDetailListInfo.Count; } WaitApproveStaticAndDetailInfo.WaitApproveStatic = new WaitApproveStaticEntity(WaitApproveDetailItemCount); WaitApproveStaticAndDetailInfo.WaitApproveList = WaitApproveDetailListInfo; return(Ok(WaitApproveStaticAndDetailInfo)); } }
public async Task <IActionResult> SignByFlowID([FromBody] SingleSignActionBody SingleSignActionInfo) { string FlowID = SingleSignActionInfo.FlowID.Trim(); string RowUnidArrayString = string.Empty; string SignID = SingleSignActionInfo.SignID; string SingRemark = string.Empty; string NoteArrayString = string.Empty; string IsFinish = "3"; // 簽准:IsFinish = '1';退回:IsFinish = '3' if (SingleSignActionInfo.IsApproval == "1") { IsFinish = "1"; } if (FlowID == string.Empty || SignID == string.Empty || (SingleSignActionInfo.IsApproval == string.Empty)) { return(StatusCode(401)); } int rowCount = 0; foreach (SignLogDetailEntity thisSignLogDetail in SingleSignActionInfo.SignLogDetailInfo) { string currentRowUnid = thisSignLogDetail.RowUnid.Trim(); string currentSingRemark = thisSignLogDetail.Note.Trim().Replace(",", ","); if (rowCount == 0) { RowUnidArrayString = currentRowUnid; NoteArrayString = currentSingRemark; } else { RowUnidArrayString += "," + currentRowUnid; NoteArrayString += "," + currentSingRemark; } rowCount++; } // ===================================================================== string[] param = new[] { FlowID, RowUnidArrayString, SignID, SingRemark, NoteArrayString, IsFinish }; string sSQL = @"EXEC [whs].[usp_UpdatedProcessStatusBySign] @FlowID = {0}, @RowUnid = {1}, @SignID = {2}, @SingRemark = {3}, @Note = {4}, @IsFinish = {5}, @UpdatedBy = NULL"; var MyHrisDB = new HrisDbContext(); try { await MyHrisDB.Database.ExecuteSqlRawAsync(sSQL, param); } catch (Exception ex) { return(StatusCode(501)); } return(Ok()); }
public IActionResult SignBatchApproval([FromBody] BatchSignApprovalEntity BatchSignApprovalInfo) { string FlowIDArrayString = string.Empty; string SignID = BatchSignApprovalInfo.SignID.Trim(); string SingRemark = "SP主管批次核准"; string UpdatedBy = SignID; if (SignID.Length != 6) { return(StatusCode(401)); } // ===================================================================================== if (BatchSignApprovalInfo.SignBatchDetailList != null && BatchSignApprovalInfo.SignBatchDetailList.Count > 0) { foreach (SignBatchDetailEntity SignBatchDetailInfo in BatchSignApprovalInfo.SignBatchDetailList) { string currentFlowID = SignBatchDetailInfo.FlowID.Trim(); if (FlowIDArrayString == string.Empty) { FlowIDArrayString = currentFlowID; } else { FlowIDArrayString = FlowIDArrayString + "," + currentFlowID; } } } else { return(StatusCode(401)); } // ================================================================== string sSQL = @"EXEC [whs].[usp_UpdatedProcessStatusBySignBatch] @FlowID = {0}, @SignID = {1}, @SingRemark = {2}, @UpdatedBy = NULL"; string[] param = new[] { FlowIDArrayString, SignID, SingRemark, UpdatedBy }; var MyHrisDB = new HrisDbContext(); try { MyHrisDB.Database.ExecuteSqlRaw(sSQL, param); } catch (Exception ex) { return(StatusCode(501)); } return(Ok()); }
public async Task <ActionResult <EmpLeaveWithWorkDateDetailEntity> > GetEmpLeaveWorkDates(string EmpID, string WorkDateNo) { bool bolInValid = false; // 紀錄程序是否錯誤 string strRetMsg = string.Empty; // 紀錄程序錯誤訊息 ActionResult retStatusCode = null; // 回傳StatusCode DateTime dteWorkdate = default(DateTime); // 傳入日期參數 DateTime dteWeekStartDate = default(DateTime); // 當週起始日期 DateTime dteWeekStartEnd = default(DateTime); // 當週結束日期 HrisDbContext MyHrisDB = null; string sSQL = string.Empty; string RowUnid = string.Empty; // 傳入日期所對應之RowUnid // 宣告回傳類別 EmpLeaveWithWorkDateDetailEntity EmpLeaveWithWorkDateDetailInfo = new EmpLeaveWithWorkDateDetailEntity(); // 初始化 ======================================================================== // 取得傳入參數 string WorkDate = WorkDateNo.Substring(0, 4) + "/" + WorkDateNo.Substring(4, 2) + "/" + WorkDateNo.Substring(6, 2); if (DateTime.TryParse(WorkDate, out dteWorkdate) == false) { bolInValid = true; retStatusCode = StatusCode(401); } else { int WeekStartOffset = (int)dteWorkdate.DayOfWeek; dteWeekStartDate = dteWorkdate.AddDays(-1 * WeekStartOffset); dteWeekStartEnd = dteWeekStartDate.AddDays(6); } // 取得DB資料 ======================================================================== if (!bolInValid) { // 實例化資料庫類別 MyHrisDB = new HrisDbContext(); // 取得當日填報資料代碼 RowUnid = GetWorkingHoursRowUnidByWorkingDate(EmpID, dteWorkdate); if (RowUnid == null || RowUnid.Trim() == string.Empty) { bolInValid = true; retStatusCode = NotFound(EmpLeaveWithWorkDateDetailInfo); } } // 取得:員工單日假單、加班單&判斷員工單日工時 ====================================== // 優先執行:此SP將更新 [WorkingHours].[FilledHours] // 以同步方式呼叫 if (!bolInValid) { sSQL = "EXEC [whs].[usp_GetEmpLeavebyWorkDate] {0}, {1}"; try { EmpLeaveWithWorkDateDetailInfo.EmpLeaveList = MyHrisDB.EmpLeavebyWorkDateEntitys .FromSqlRaw(sSQL, EmpID, WorkDate) .ToList(); } catch (Exception ex) { bolInValid = true; retStatusCode = StatusCode(501, EmpLeaveWithWorkDateDetailInfo); } } // 取得:單日填報統計 =============================================================== if (!bolInValid) { sSQL = "EXEC [whs].[usp_GetWorkingDateAllDetail] {0}"; try { var EmpWorkdateListInfo = await MyHrisDB.EmpWorkdateEntitys .FromSqlRaw(sSQL, RowUnid) .ToListAsync(); if (EmpWorkdateListInfo != null && EmpWorkdateListInfo.Count > 0) { EmpLeaveWithWorkDateDetailInfo.WorkDate = EmpWorkdateListInfo.First(); } } catch (Exception ex) { bolInValid = true; retStatusCode = StatusCode(501, EmpLeaveWithWorkDateDetailInfo); } } // 取得:員工週間申請狀態 ============================================================ if (!bolInValid) { string sWeekStartDate = dteWeekStartDate.ToString("yyyy/MM/dd"); string sWeekEndDate = dteWeekStartEnd.ToString("yyyy/MM/dd"); sSQL = "EXEC [whs].[usp_GetWorkingDate] {0}, {1}, {2}"; try { var EmpWorkingDateStatusListsInfo = await MyHrisDB.EmpWorkingDateStatusLists .FromSqlRaw(sSQL, EmpID, sWeekStartDate, sWeekEndDate) .ToListAsync(); EmpLeaveWithWorkDateDetailInfo.WeekList = EmpWorkingDateStatusListsInfo; } catch (Exception ex) { bolInValid = true; retStatusCode = StatusCode(501, EmpLeaveWithWorkDateDetailInfo); } } // 取得:單日填報工時明細 ======================================================= if (!bolInValid) { sSQL = "EXEC [whs].[usp_GetWorkingDateAllDetail_Detail] {0}"; try { EmpLeaveWithWorkDateDetailInfo.DetailList = await MyHrisDB.WorkingDateAllDetailEntitys .FromSqlRaw(sSQL, RowUnid) .ToListAsync(); retStatusCode = Ok(EmpLeaveWithWorkDateDetailInfo); } catch (Exception ex) { bolInValid = true; retStatusCode = StatusCode(501, EmpLeaveWithWorkDateDetailInfo); } } // API 回傳 ============================================================== return(retStatusCode); }
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); }
public async Task <ActionResult <List <WorkingDateEntity> > > GetWorkingDate(string EmpID, string StartDateNo, string EndDateNo) { bool bolInValid = false; List <WorkingDateEntity> WorkingDateList = new List <WorkingDateEntity>(); ActionResult retStatusResult = null; // 傳入參數設定與檢查 ========================================================== string StartDate = StartDateNo.Substring(0, 4) + "/" + StartDateNo.Substring(4, 2) + "/" + StartDateNo.Substring(6, 2); string EndDate = EndDateNo.Substring(0, 4) + "/" + EndDateNo.Substring(4, 2) + "/" + EndDateNo.Substring(6, 2); if (DateTime.TryParse(StartDate, out _) == false) { bolInValid = true; retStatusResult = StatusCode(401, WorkingDateList); } if (DateTime.TryParse(EndDate, out _) == false) { bolInValid = true; retStatusResult = StatusCode(401, WorkingDateList); } // 取得資料 ========================================================== if (!bolInValid) { string sSQL = "EXEC [whs].[usp_GetWorkingDate] {0}, {1}, {2}"; var MyHrisDB = new HrisDbContext(); try { WorkingDateList = await MyHrisDB.WorkingDateEntitys .FromSqlRaw(sSQL, EmpID, StartDate, EndDate) .ToListAsync(); } catch (Exception ex) { bolInValid = true; retStatusResult = StatusCode(501, WorkingDateList); } } if (bolInValid) { return(retStatusResult); } else { return(Ok(WorkingDateList)); } }