public IActionResult Post(IndividualProjectPage page)
        {
            Project project = new Project(page.ID, page.Name, page.desc, page.startDate, page.endDate, page.completion, page.salaryBudget, page.totalInvoice, page.materialBudget, page.spendToDate,
                                          page.progressSurveySent, page.progressSurveyResult,
                                          page.followupSurveySent, page.followupSurveyResult, page.isProposal, page.costMultiplier, page.isUnderISO13485, page.businessCode, page.lead[0].name);

            // <-- in the param
            _projectRepository.Add(project);

            for (int i = 0; i < page.phaseArr.Count; i++)
            {
                PhaseArr currentPhaseArr = page.phaseArr[i];
                Phase    phase           = new Phase(currentPhaseArr.phaseID, page.ID, currentPhaseArr.name, currentPhaseArr.startDate, currentPhaseArr.endDate, currentPhaseArr.isRecordDone, currentPhaseArr.predictedDurationInWeeks,
                                                     currentPhaseArr.actualDurationInWeeks, currentPhaseArr.impact, 0, 0, null);
                phase.MaterialProjectedBudget = page.material[i].projectedBudget;
                phase.MaterialActualBudget    = page.material[i].actualBudget;
                phase.MaterialImpact          = page.material[i].impact;
                _phaseRepository.Add(phase);
            }

            EmployeeAssignment ea = new EmployeeAssignment();

            for (int i = 0; i < page.employeeSalaryList.Count; i++)
            {
                ea.EmployeeId = page.employeeSalaryList[i].empID;

                ea.Position         = "somePosition"; //hardcoded for now?
                ea.SalaryMultiplier = page.costMultiplier;

                for (int j = 0; j < page.employeeSalaryList[i].phaseDetailsList.Count; j++)
                {
                    PhaseDetails currentPhaseDetails = page.employeeSalaryList[i].phaseDetailsList[j];
                    ea.PhaseId        = currentPhaseDetails.phaseID;
                    ea.ActualHours    = currentPhaseDetails.actualHr;
                    ea.ProjectedHours = currentPhaseDetails.budgetHr;
                    ea.Impact         = currentPhaseDetails.impact;
                    for (int z = 0; z < page.lead.Count; z++)
                    {
                        if (ea.EmployeeId == page.lead[z].empID)
                        {
                            ea.IsProjectManager = true;
                        }
                        else
                        {
                            ea.IsProjectManager = false;
                        }
                    }
                    _employeeAssignmentRepository.Add(ea);
                }
            }

            ProjectedWorkload pw = new ProjectedWorkload();

            for (int i = 0; i < page.workloadArr.Count; i++)
            {
                WorkloadArr currentWorkloadArr = page.workloadArr[i];
                foreach (Employee e in _employeeRepository.GetAll())
                {
                    if (e.EmployeeId == currentWorkloadArr.empID)
                    {
                        pw.ProjectId  = page.ID;
                        pw.EmployeeId = e.EmployeeId;
                        for (int k = 0; k < 6; k++)
                        {
                            pw.Month = DateTime.Now.AddMonths(k).Month;
                            pw.Year  = DateTime.Now.AddMonths(k).Year;
                            //pw.Month = ControllerHelper.CalculateCurrentMonth(currentMonth, k-1);
                            pw.Hours = currentWorkloadArr.getHoursWorked(k + 1);
                            _projectedWorkloadRepository.Add(pw);
                        }
                    }
                }
            }

            foreach (InvoiceArr i in page.invoiceArr)
            {
                Invoice invoice = new Invoice(page.ID, "placeholdername", i.date, i.amount);
                _invoiceRepository.Add(invoice);
            }


            return(new OkObjectResult(201));
        }
        public IActionResult GetById(int id)
        {
            IndividualProjectPage individualProjectPage = new IndividualProjectPage
            {
                ID                     = _projectRepository.Get(id).ProjectId,
                Name                   = _projectRepository.Get(id).ProjectName,
                desc                   = _projectRepository.Get(id).ProjectDescription,
                salaryBudget           = _projectRepository.Get(id).SalaryBudget,
                totalInvoice           = _projectRepository.Get(id).TotalInvoice,
                materialBudget         = _projectRepository.Get(id).MaterialBudget,
                spendToDate            = _projectRepository.Get(id).SpentToDate,
                startDate              = _projectRepository.Get(id).ProjectStartDate,
                endDate                = _projectRepository.Get(id).ProjectEndDate,
                completion             = _projectRepository.Get(id).PercentageComplete,
                recoredStoredCompleted = _projectRepository.Get(id).recordStoredCompleted,
                progressSurveyResult   = _projectRepository.Get(id).IsInProgressSurveyComplete,
                progressSurveySent     = _projectRepository.Get(id).IsInProgressSurveySent,
                followupSurveyResult   = _projectRepository.Get(id).IsFollowUpSurveyComplete,
                followupSurveySent     = _projectRepository.Get(id).IsFollowUpSurveySent,
                isProposal             = _projectRepository.Get(id).IsProposal,
                isUnderISO13485        = _projectRepository.Get(id).isUnderISO13485,
                businessCode           = _projectRepository.Get(id).BusinessCode,
                costMultiplier         = _projectRepository.Get(id).CostMultiplier
            };

            HashSet <Lead>   leadList   = new HashSet <Lead>();
            HashSet <Member> memberList = new HashSet <Member>();

            foreach (EmployeeAssignment item in _employeeAssignmentRepository.GetAll())
            {
                if (item.IsProjectManager)
                {
                    foreach (Employee employee in _employeeRepository.GetAll())
                    {
                        if (employee.EmployeeId == item.EmployeeId)
                        {
                            leadList.Add(new Lead(item.EmployeeId, employee.Name, employee.Salary));
                        }
                    }
                }
                else
                {
                    foreach (Employee employee in _employeeRepository.GetAll())
                    {
                        if (employee.EmployeeId == item.EmployeeId)
                        {
                            memberList.Add(new Member(item.EmployeeId, employee.Name, employee.Salary));
                        }
                    }
                }
            }
            individualProjectPage.lead   = leadList.ToList();
            individualProjectPage.member = memberList.ToList();

            individualProjectPage.phaseArr = new List <PhaseArr>();

            foreach (Phase phase in _phaseRepository.GetAll())
            {
                if (phase.ProjectId == id)
                {
                    individualProjectPage.phaseArr.Add(new PhaseArr(phase.PhaseId, phase.Name, phase.StartDate,
                                                                    phase.EndDate, phase.IsRecordDone, phase.PredictedDurationInWeeks, phase.ActualDurationInWeeks,
                                                                    phase.Impact));
                }
            }

            individualProjectPage.workloadArr = new List <WorkloadArr>();
            WorkloadArr currentWorkloadArr = new WorkloadArr();

            foreach (Project proj in _projectRepository.GetAll())
            {
                if (proj.ProjectId == id)
                {
                    foreach (Employee emp in _employeeRepository.GetAll())
                    {
                        ProjectedWorkload currentProjectedWorkload = _projectedWorkloadRepository.Get(proj, emp, DateTime.Now.Month,
                                                                                                      DateTime.Now.Year);
                        if (currentProjectedWorkload != null)
                        {
                            for (int k = 0; k < 6; k++)
                            {
                                int currentMonth = DateTime.Now.AddMonths(k).Month;
                                int currentYear  = DateTime.Now.AddMonths(k).Year;

                                if (emp.EmployeeId == _projectedWorkloadRepository
                                    .Get(proj, emp, currentMonth, currentYear).EmployeeId &&
                                    proj.ProjectId == _projectedWorkloadRepository
                                    .Get(proj, emp, currentMonth, currentYear).ProjectId)
                                {
                                    currentWorkloadArr.empID   = emp.EmployeeId;
                                    currentWorkloadArr.empName = emp.Name;
                                    currentWorkloadArr.SetSpecificMonth(k + 1, _projectedWorkloadRepository
                                                                        .Get(proj, emp, currentMonth, currentYear).Hours);
                                }
                            }
                            individualProjectPage.workloadArr.Add(new WorkloadArr(currentWorkloadArr.empID, currentWorkloadArr.empName, currentWorkloadArr.month1, currentWorkloadArr.month2,
                                                                                  currentWorkloadArr.month3, currentWorkloadArr.month4, currentWorkloadArr.month5, currentWorkloadArr.month6));
                        }
                    }
                }
            }

            individualProjectPage.invoiceArr = new List <InvoiceArr>();
            foreach (Invoice i in _invoiceRepository.GetAll())
            {
                if (i.ProjectId == id)
                {
                    individualProjectPage.invoiceArr.Add(new InvoiceArr(i.InvoiceAmount, i.InvoiceTime));
                }
            }

            individualProjectPage.material = new List <Material>();

            foreach (Phase phase in _phaseRepository.GetAll())
            {
                if (phase.ProjectId == id)
                {
                    individualProjectPage.material.Add(new Material(phase.PhaseId, phase.Name, phase.MaterialActualBudget,
                                                                    phase.MaterialProjectedBudget, phase.MaterialImpact));
                }
            }

            individualProjectPage.employeeSalaryList = new List <EmployeeSalary>();

            foreach (Employee emp in _employeeRepository.GetAll())
            {
                List <PhaseDetails> phaseDetailsList = new List <PhaseDetails>();
                foreach (Phase phase in _phaseRepository.GetAll())
                {
                    if (phase.ProjectId == id && _employeeAssignmentRepository.Get(phase.PhaseId, emp.EmployeeId) != null)
                    {
                        EmployeeAssignment currentEmployeeAssignment = _employeeAssignmentRepository.Get(phase.PhaseId, emp.EmployeeId);
                        phaseDetailsList.Add(new PhaseDetails(phase.PhaseId, phase.Name, currentEmployeeAssignment.ProjectedHours,
                                                              currentEmployeeAssignment.ActualHours, currentEmployeeAssignment.Impact));
                    }
                }
                if (phaseDetailsList.Count != 0)  //to prevent all the employees from being added to the employeeSalaryList.  Only employees that are working on the project will be added.
                {
                    individualProjectPage.employeeSalaryList.Add(new EmployeeSalary(emp.EmployeeId, emp.Name, emp.Salary, phaseDetailsList));
                }
            }

            return(Ok(individualProjectPage));
        }