コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="HeadCount"></param>
        /// <returns></returns>
        public int UpdateHeadCount(List <HeadCountDTO> target, int typeID, int year, int projectID)
        {
            var source = GetHeadCountByType(typeID, year, projectID);

            EmployeeRoleRepository employeeRepository = new EmployeeRoleRepository(BaseRepository.SystemUserID);
            CountryRepository      countryRepository  = new CountryRepository(BaseRepository.SystemUserID);

            // find and insert new items.
            var newItems = target.Except(source, new HeadCountDTOComparer());

            foreach (HeadCountDTO headCountDTO in newItems)
            {
                HeadCount HeadCount = new HeadCount();

                HeadCount.ProjectID          = projectID;
                HeadCount.EmployeeRoleTypeID = typeID;
                HeadCount.Year = year;

                HeadCount.EmployeeRoleID = employeeRepository.GetEmployeeRole(headCountDTO.EmployeeRole).ID;
                HeadCount.CountryID      = countryRepository.GetCountry(headCountDTO.Country).ID;

                HeadCount.Incremental = DataUtility.GetBooleanString(headCountDTO.Incremental);

                HeadCount.Comment = headCountDTO.Comment;
                HeadCount.Month01 = DataUtility.GetDecimalValue(headCountDTO.Month01);
                HeadCount.Month02 = DataUtility.GetDecimalValue(headCountDTO.Month02);
                HeadCount.Month03 = DataUtility.GetDecimalValue(headCountDTO.Month03);
                HeadCount.Month04 = DataUtility.GetDecimalValue(headCountDTO.Month04);
                HeadCount.Month05 = DataUtility.GetDecimalValue(headCountDTO.Month05);
                HeadCount.Month06 = DataUtility.GetDecimalValue(headCountDTO.Month06);
                HeadCount.Month07 = DataUtility.GetDecimalValue(headCountDTO.Month07);
                HeadCount.Month08 = DataUtility.GetDecimalValue(headCountDTO.Month08);
                HeadCount.Month09 = DataUtility.GetDecimalValue(headCountDTO.Month09);
                HeadCount.Month10 = DataUtility.GetDecimalValue(headCountDTO.Month10);
                HeadCount.Month11 = DataUtility.GetDecimalValue(headCountDTO.Month11);
                HeadCount.Month12 = DataUtility.GetDecimalValue(headCountDTO.Month12);

                CreateHeadCount(HeadCount);
            }


            // find and insert new items.
            var updateItems = target.Union(source, new HeadCountDTOComparer());

            foreach (HeadCountDTO headCountDTO in updateItems)
            {
                int employeeRoleID = employeeRepository.GetEmployeeRole(headCountDTO.EmployeeRole).ID;

                HeadCount HeadCount = GetHeadCount(typeID, year, projectID, employeeRoleID);

                HeadCount.EmployeeRoleTypeID = typeID;
                HeadCount.Year      = year;
                HeadCount.ProjectID = projectID;

                HeadCount.EmployeeRoleID = employeeRoleID;
                HeadCount.CountryID      = countryRepository.GetCountry(headCountDTO.Country).ID;

                HeadCount.Incremental = DataUtility.GetBooleanString(headCountDTO.Incremental);

                HeadCount.Comment = headCountDTO.Comment;
                HeadCount.Month01 = DataUtility.GetDecimalValue(headCountDTO.Month01);
                HeadCount.Month02 = DataUtility.GetDecimalValue(headCountDTO.Month02);
                HeadCount.Month03 = DataUtility.GetDecimalValue(headCountDTO.Month03);
                HeadCount.Month04 = DataUtility.GetDecimalValue(headCountDTO.Month04);
                HeadCount.Month05 = DataUtility.GetDecimalValue(headCountDTO.Month05);
                HeadCount.Month06 = DataUtility.GetDecimalValue(headCountDTO.Month06);
                HeadCount.Month07 = DataUtility.GetDecimalValue(headCountDTO.Month07);
                HeadCount.Month08 = DataUtility.GetDecimalValue(headCountDTO.Month08);
                HeadCount.Month09 = DataUtility.GetDecimalValue(headCountDTO.Month09);
                HeadCount.Month10 = DataUtility.GetDecimalValue(headCountDTO.Month10);
                HeadCount.Month11 = DataUtility.GetDecimalValue(headCountDTO.Month11);
                HeadCount.Month12 = DataUtility.GetDecimalValue(headCountDTO.Month12);

                UpdateHeadCount(HeadCount);
            }


            // find and delete items
            var deleteItems = source.Except(target, new HeadCountDTOComparer());

            foreach (HeadCountDTO HeadCountDTO in deleteItems)
            {
                int employeeRoleID = employeeRepository.GetEmployeeRole(HeadCountDTO.EmployeeRole).ID;

                HeadCount HeadCount = GetHeadCount(typeID, year, projectID, employeeRoleID);

                DeleteHeadCount(HeadCount.ID);
            }

            ctx.SaveChanges();

            return(0);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ExpenseDetail"></param>
        /// <returns></returns>
        public int UpdateExpenseDetail(List <ExpenseDetailDTO> target, int typeID, int year, int projectID)
        {
            var source = GetExpenseDetailByType(typeID, year, projectID);

            ExpenseRepository expenseRepository = new ExpenseRepository(BaseRepository.SystemUserID);
            CountryRepository countryRepository = new CountryRepository(BaseRepository.SystemUserID);

            // find and insert new items.
            var newItems = target.Except(source, new ExpenseDetailDTOComparer());

            foreach (ExpenseDetailDTO ExpenseDetailDTO in newItems)
            {
                ExpenseDetail ExpenseDetail = new ExpenseDetail();

                ExpenseDetail.ProjectID     = projectID;
                ExpenseDetail.ExpenseTypeID = typeID;
                ExpenseDetail.Year          = year;

                ExpenseDetail.ExpenseID = expenseRepository.GetExpense(ExpenseDetailDTO.Expense).ID;
                ExpenseDetail.CountryID = countryRepository.GetCountry(ExpenseDetailDTO.Country).ID;

                ExpenseDetail.Comment = ExpenseDetailDTO.Comment;
                ExpenseDetail.Month01 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month01);
                ExpenseDetail.Month02 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month02);
                ExpenseDetail.Month03 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month03);
                ExpenseDetail.Month04 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month04);
                ExpenseDetail.Month05 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month05);
                ExpenseDetail.Month06 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month06);
                ExpenseDetail.Month07 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month07);
                ExpenseDetail.Month08 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month08);
                ExpenseDetail.Month09 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month09);
                ExpenseDetail.Month10 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month10);
                ExpenseDetail.Month11 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month11);
                ExpenseDetail.Month12 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month12);

                CreateExpenseDetail(ExpenseDetail);
            }


            // find and insert new items.
            var updateItems = target.Union(source, new ExpenseDetailDTOComparer());

            foreach (ExpenseDetailDTO ExpenseDetailDTO in updateItems)
            {
                int expenseID = expenseRepository.GetExpense(ExpenseDetailDTO.Expense).ID;

                ExpenseDetail ExpenseDetail = GetExpenseDetail(typeID, year, projectID, expenseID);

                ExpenseDetail.ExpenseTypeID = typeID;
                ExpenseDetail.Year          = year;
                ExpenseDetail.ProjectID     = projectID;

                ExpenseDetail.ExpenseID = expenseID;
                ExpenseDetail.CountryID = countryRepository.GetCountry(ExpenseDetailDTO.Country).ID;

                ExpenseDetail.Comment = ExpenseDetailDTO.Comment;
                ExpenseDetail.Month01 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month01);
                ExpenseDetail.Month02 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month02);
                ExpenseDetail.Month03 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month03);
                ExpenseDetail.Month04 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month04);
                ExpenseDetail.Month05 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month05);
                ExpenseDetail.Month06 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month06);
                ExpenseDetail.Month07 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month07);
                ExpenseDetail.Month08 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month08);
                ExpenseDetail.Month09 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month09);
                ExpenseDetail.Month10 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month10);
                ExpenseDetail.Month11 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month11);
                ExpenseDetail.Month12 = DataUtility.GetDecimalValue(ExpenseDetailDTO.Month12);

                UpdateExpenseDetail(ExpenseDetail);
            }


            // find and delete items
            var deleteItems = source.Except(target, new ExpenseDetailDTOComparer());

            foreach (ExpenseDetailDTO ExpenseDetailDTO in deleteItems)
            {
                int expenseID = expenseRepository.GetExpense(ExpenseDetailDTO.Expense).ID;

                ExpenseDetail ExpenseDetail = GetExpenseDetail(typeID, year, projectID, expenseID);

                DeleteExpenseDetail(ExpenseDetail.ID);
            }

            ctx.SaveChanges();

            return(0);
        }