Exemple #1
0
        public LegalForm CreateNewLegalForm(LegalForm lf)
        {
            LegalForm legalform = EmpContractChangesDbContext.LegalForms.Add(lf);

            EmpContractChangesDbContext.SaveChanges();

            return(legalform);
        }
Exemple #2
0
        public void InsertEmployeeContractChanges(EmployeeContractChanges contract, int employeeID, bool editing = false, bool survey = false)
        {
            Employee employeeToUpdate = EmpContractChangesDbContext.Employees
                                        .FirstOrDefault(x => x.ID == employeeID);

            //Only supposed to do this when user is filling out survey.
            if (survey)
            {
                employeeToUpdate.LastUpdate = DateTime.Now;
            }

            EmployeeContractChanges eCC    = new EmployeeContractChanges();
            EmployeeContractChanges lastCF = GetLCF(employeeToUpdate.ID);


            //Check if contract with given id exists, if it does do block 2, if it does not do block 1 and 2.
            bool contractInProgress = false;
            bool contractExists     = false;
            int  newChangeLogID     = 1;

            if (lastCF != null)
            {
                contractExists = EmpContractChangesDbContext
                                 .EmployeeContractChanges.Find(lastCF.ID) != null ? true : false;



                contractInProgress = CFInProgress(employeeToUpdate);

                newChangeLogID = lastCF.ChangeLogID + 1;
            }



            LegalForm legalform = new LegalForm()
            {
                FilePath = "N/A", Reason = "N/A"
            };

            if (!contractExists || !contractInProgress)
            {//1 - Brand new entry into EmployeeContractChange table.
                legalform = CreateNewLegalForm(legalform);

                eCC.LegalForm    = legalform;
                eCC.LegalFormsID = legalform.ID;
                eCC.StatusID     = 1;
                eCC.EmployeeID   = employeeToUpdate.ID;
                eCC.ChangeLogID  = !contractInProgress ? newChangeLogID : 1;
                eCC.NewAddress   = employeeToUpdate.Address;
                eCC.NewCity      = employeeToUpdate.City;
                eCC.NewCountry   = employeeToUpdate.Country;
                eCC.NewEmail     = employeeToUpdate.Email;
                eCC.NewHomePhone = employeeToUpdate.HomePhone;
                eCC.NewLastName  = employeeToUpdate.LastName;
                eCC.NewState     = employeeToUpdate.State;
                eCC.NewZipcode   = employeeToUpdate.Zipcode;
                eCC.DateCreated  = DateTime.Now;

                EmpContractChangesDbContext.EmployeeContractChanges.Add(eCC);
                EmpContractChangesDbContext.SaveChanges();
            }


            EmployeeContractChanges eCC_NEW = new EmployeeContractChanges();

            ///2
            eCC_NEW.LegalFormsID = lastCF != null ? lastCF.LegalFormsID : legalform.ID;
            eCC_NEW.StatusID     = contract.StatusID == 0 ? 1 : contract.StatusID; //WILL BE PROVIDING STATUS
            eCC_NEW.EmployeeID   = employeeToUpdate.ID;
            eCC_NEW.ChangeLogID  = (!contractExists || !contractInProgress) ? eCC.ChangeLogID : lastCF.ChangeLogID;
            eCC_NEW.NewAddress   = contract.NewAddress;
            eCC_NEW.NewCity      = contract.NewCity;
            eCC_NEW.NewCountry   = contract.NewCountry;
            eCC_NEW.NewEmail     = contract.NewEmail;
            eCC_NEW.NewHomePhone = contract.NewHomePhone;
            eCC_NEW.NewLastName  = contract.NewLastName;
            eCC_NEW.NewState     = contract.NewState;
            eCC_NEW.NewZipcode   = contract.NewZipcode;
            eCC_NEW.DateCreated  = DateTime.Now;


            EmpContractChangesDbContext.EmployeeContractChanges.Add(eCC_NEW);
            EmpContractChangesDbContext.SaveChanges();
        }