Ejemplo n.º 1
0
        /// <summary>
        /// Save
        /// </summary>
        /// <returns>employeeId</returns>
        public int Save()
        {
            EmployeesAddTDS employeeAddChanges = (EmployeesAddTDS)Data.GetChanges();
            int employeeId = 0;

            if (employeeAddChanges != null)
            {
                if (employeeAddChanges.EmployeeAdd.Rows.Count > 0)
                {
                    EmployeeAddGateway employeeNavigatorGateway = new EmployeeAddGateway(employeeAddChanges);

                    // Update employees
                    foreach (EmployeesAddTDS.EmployeeAddRow row in (EmployeesAddTDS.EmployeeAddDataTable)employeeAddChanges.EmployeeAdd)
                    {
                        // Insert new employees
                        if ((!row.Deleted) && (!row.InDatabase))
                        {
                            Employee employee = new Employee(null);
                            int? loginId = null; if (!row.IsLoginIDNull()) loginId = row.LoginID;
                            int? contactsId = null; if (!row.IsContactsIDNull()) contactsId = row.ContactsID;
                            string middleInitial = ""; if (!row.IsMiddleInitialNull()) middleInitial = row.MiddleInitial;
                            string email = ""; if (!row.IseMailNull()) email = row.eMail;
                            bool assignableSrs = row.AssignableSRS;
                            string jobClass = ""; if (!row.IsJobClassTypeNull()) jobClass = row.JobClassType;
                            string personalAgencyName = ""; if (!row.IsPersonalAgencyNameNull()) personalAgencyName = row.PersonalAgencyName;
                            bool isVacationsManager = row.IsVacationsManager;
                            bool approveTimesheets = row.ApproveTimesheets;
                            decimal? bourdenFactor = null; if (!row.IsBourdenFactorNull()) bourdenFactor = (decimal)row.BourdenFactor;
                            decimal? usHealthBenefitFactor = null; if (!row.IsUSHealthBenefitFactorNull()) usHealthBenefitFactor = (decimal)row.USHealthBenefitFactor;
                            decimal? benefitFactorCad = null; if (!row.IsBenefitFactorCadNull()) benefitFactorCad = (decimal)row.BenefitFactorCad;
                            decimal? benefitFactorUsd = null; if (!row.IsBenefitFactorUsdNull()) benefitFactorUsd = (decimal)row.BenefitFactorUsd;
                            string crew = ""; //TODO CREW

                            employeeId = employee.InsertDirect(loginId, contactsId, row.FullName, row.FirstName, middleInitial, row.LastName, row.Type, row.State, row.IsSalesman, row.RequestProjectTime, row.Deleted, row.Salaried, email, assignableSrs, jobClass, row.Category, personalAgencyName, isVacationsManager, approveTimesheets, bourdenFactor, usHealthBenefitFactor, benefitFactorCad, benefitFactorUsd, crew);

                            // Employee Categories Approve Timesheets
                            EmployeeCategoryApproveTimesheets employeeCategoryApproveTimesheets = new EmployeeCategoryApproveTimesheets(null);
                            employeeCategoryApproveTimesheets.InsertDirect(employeeId, "Field", false, false);
                            employeeCategoryApproveTimesheets.InsertDirect(employeeId, "Field 44", false, false);
                            employeeCategoryApproveTimesheets.InsertDirect(employeeId, "Mechanic/Manufactoring", false, false);
                            employeeCategoryApproveTimesheets.InsertDirect(employeeId, "Office/Admin", false, false);
                            employeeCategoryApproveTimesheets.InsertDirect(employeeId, "Special Forces", false, false);
                        }
                    }
                }
            }

            return employeeId;
        }
        /// <summary>
        /// Save all categories approve timesheets to database (direct)
        /// </summary>
        public void Save()
        {
            EmployeeInformationTDS categoryApproveTimesheetsInformationChanges = (EmployeeInformationTDS)Data.GetChanges();

            if (categoryApproveTimesheetsInformationChanges.CategoryApproveTimesheetsInformation.Rows.Count > 0)
            {
                EmployeeInformationCategoryApproveTimesheetsInformationGateway employeeInformationCategoryApproveTimesheetsInformationGateway = new EmployeeInformationCategoryApproveTimesheetsInformationGateway(categoryApproveTimesheetsInformationChanges);

                foreach (EmployeeInformationTDS.CategoryApproveTimesheetsInformationRow row in (EmployeeInformationTDS.CategoryApproveTimesheetsInformationDataTable)categoryApproveTimesheetsInformationChanges.CategoryApproveTimesheetsInformation)
                {
                    int employeeId = row.EmployeeID;
                    string category = row.Category;
                    bool deleted = false;

                    // original values
                    bool originalApproveTimesheets = employeeInformationCategoryApproveTimesheetsInformationGateway.GetApproveTimesheetsOriginal(employeeId, category);

                    // new values
                    bool newApproveTimesheets = employeeInformationCategoryApproveTimesheetsInformationGateway.GetApproveTimesheets(employeeId, category);

                    EmployeeCategoryApproveTimesheets employeeCategoryApproveTimesheets = new EmployeeCategoryApproveTimesheets(null);
                    int rowsAffected = employeeCategoryApproveTimesheets.UpdateDirect(employeeId, category, originalApproveTimesheets, deleted, employeeId, category, newApproveTimesheets, deleted);

                    if (rowsAffected == 0)
                    {
                        employeeCategoryApproveTimesheets.InsertDirect(employeeId, category, newApproveTimesheets, deleted);
                    }
                }
            }
        }