private void InitChildren() { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKLeaveInfoID, PKLeaveInfoID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.IsDeleted, Convert.ToString(0), SearchComparator.Equal, SearchType.SearchNotString)); timeDurationList = CommonDAL <TimeDurationInfo> .GetObjects(conditions); conditions.Clear(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKLeaveTypeID, FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); leaveCategory = CommonDAL <LeaveType> .GetSingleObject(conditions); conditions.Clear(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKEmployeeID, FKReportManagerID.ToString(), SearchComparator.Equal, SearchType.SearchString)); manager = CommonDAL <Employee> .GetSingleObject(conditions); conditions.Clear(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKEmployeeID, FKSubmitEmployeeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); submitter = CommonDAL <Employee> .GetSingleObject(conditions); }
protected override void Update() { using (TransactionScope ts = new TransactionScope()) { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKLeaveInfoID, PKLeaveInfoID.ToString(), SearchComparator.Equal, SearchType.SearchString)); CommonDAL <LeaveInfo> .Update(this, conditions); foreach (TimeDurationInfo item in timeDurationList) { if (item.IsNew) { item.FKLeaveInfoID = this.PKLeaveInfoID; } item.Save(); } //#region For transact unit test //throw new Exception(); //#endregion if (this.PreStatus != LeaveStatus.Accepted && this.Status == LeaveStatus.Accepted || this.status == LeaveStatus.Rejected && this.PreStatus == LeaveStatus.Accepted) { int year; double usedHours = GetDurationHours(timeDurationList, out year); if (usedHours != 0 && year != 0) { conditions.Clear(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKEmployeeID, FKSubmitEmployeeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKLeaveTypeID, FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Year, year.ToString(), SearchComparator.Equal, SearchType.SearchNotString)); EmployeeLeaveSummary leaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions); if (null == leaveSummary) { leaveSummary = EmployeeLeaveSummary.CreateEmployeeLeaveSummary(FKSubmitEmployeeID, FKLeaveTypeID, year); } if (this.status == LeaveStatus.Rejected) { usedHours = -usedHours; } leaveSummary.UsedHours += usedHours; if (leaveSummary.UsedHours < 0) { leaveSummary.UsedHours = 0; // used hours cannot be a negative number } leaveSummary.Save(); } } ts.Complete(); } }