// 新增資料 POST: api/LeaveAppForm public async Task <APIResult> Post([FromBody] LeaveAppForm value) { #region 檢查使用者是否存在 var fooUser = await db.LOBMyUsers.FirstOrDefaultAsync(x => x.EmployeeID == value.Owner.EmployeeID); if (fooUser != null) { #region 產生請假單物件 var fooLeaveAppFormItem = new LOBLeaveAppForms() { AgentName = value.AgentName, BeginDate = value.BeginDate, ApproveResult = "尚未審核", Category = value.Category, CompleteDate = value.CompleteDate, FormDate = value.FormDate, FormsStatus = "已經送出", LeaveCause = value.LeaveCause, LOBMyUsers = fooUser, Hours = value.Hours, AgentId = value.AgentId, }; db.LOBLeaveAppForms.Add(fooLeaveAppFormItem); #endregion var fooCC = db.SaveChanges(); if (fooCC > 0) { fooResult.Success = true; fooResult.Message = $"請假單紀錄新增成功"; fooResult.TokenFail = false; fooResult.Payload = null; } else { fooResult.Success = false; fooResult.Message = $"無法新增到這筆請假單紀錄"; fooResult.TokenFail = false; fooResult.Payload = null; } } else { fooResult.Success = false; fooResult.Message = $"這筆請假單紀錄指定的使用者不存在"; fooResult.TokenFail = false; fooResult.Payload = null; } #endregion return(fooResult); }
public void InitLeaveAppForms() { #region 測試用的請假單 var fooUser1 = db.LOBMyUsers.FirstOrDefault(x => x.EmployeeID == "user1"); var fooLeaveAppForm = new LOBLeaveAppForms() { AgentName = "Vulcan", ApproveResult = "Wait", BeginDate = DateTime.Now, Category = "XX", CompleteDate = DateTime.Now, FormDate = DateTime.Now, FormsStatus = "@@", LeaveCause = "??", LOBMyUsers = fooUser1, //OwnerId = fooUser1.MyUserId, Hours = 8, }; db.LOBLeaveAppForms.Add(fooLeaveAppForm); db.SaveChanges(); #endregion }
public void Other() { int sortId = 0; #region 各資料表需要進行初始化的方法 #region 使用者資料初始化 sortId = 0; for (int i = 0; i < 10; i++) { var fooManager = new LOBMyUsers() { DepartmentName = $"部門{i}", Name = $"經理{i}", EmployeeID = $"manager{i}", Password = $"pwd{i}", ManagerId = -1, IsManager = true }; db.LOBMyUsers.Add(fooManager); db.SaveChanges(); var fooMan = $"manager{i}"; fooManager = db.LOBMyUsers.FirstOrDefault(x => x.EmployeeID == fooMan); for (int j = 1 + (i * 10); j < 11 + (i * 10); j++) { db.LOBMyUsers.Add(new LOBMyUsers() { DepartmentName = $"部門{i}", Name = $"使用者{j}", EmployeeID = $"user{j}", Password = $"pwd{j}", ManagerId = fooManager.MyUserId, IsManager = false }); db.SaveChanges(); var fooU = $"user{j}"; var fooUser = db.LOBMyUsers.FirstOrDefault(x => x.EmployeeID == fooU); #region 產生預設的請假單練習資料 for (int k = 0; k < 3; k++) { var fooBeginDate = DateTime.Now.AddDays(1).Date.AddHours(9); var fooCompleteDate = DateTime.Now.AddDays(1).Date.AddHours(18); var fooLeaveAppFormItem = new LOBLeaveAppForms() { AgentName = $"我的好友{k}", ApproveResult = "尚未審核", BeginDate = fooBeginDate, Category = "特別休假", CompleteDate = fooCompleteDate, FormDate = DateTime.Now, FormsStatus = "已經送出", LeaveCause = "休息一下", LOBMyUsers = fooUser, Hours = 8 }; db.LOBLeaveAppForms.Add(fooLeaveAppFormItem); } #endregion #region 產生預設的工作日誌紀錄 for (int k = 0; k < 3; k++) { var fooProjectName = $"專案{k}"; var fooProject = db.LOBProjects.FirstOrDefault(x => x.ProjectName == fooProjectName); var fooBeginDate = DateTime.Now.AddDays(1).Date.AddHours(9); var fooCompleteDate = DateTime.Now.AddDays(1).Date.AddHours(18); var fooWorkingLog = new LOBWorkingLogs() { LogDate = DateTime.Now, LOBProjects = fooProject, Summary = "討論上線相關準備工作", Title = "與客戶開會", LOBMyUsers = fooUser, Hours = 3 }; db.LOBWorkingLogs.Add(fooWorkingLog); } #endregion db.SaveChanges(); } } db.SaveChanges(); #endregion #endregion }