Example #1
0
        public async Task <IActionResult> PutWorkPackage(string id, WorkPackageViewModel wpViewModel)
        {
            //Get Project and ParentWpIds
            int?parentWpId = null;

            if (wpViewModel.ParentWorkPackageCode != null)
            {
                parentWpId = _workPackageRepository.GetIdByCode(wpViewModel.ParentWorkPackageCode);
            }

            int projectId = _projectRepository.GetIdByCode(wpViewModel.ProjectCode);
            int wpId      = wpViewModel.WorkPackageId;

            WorkPackage wp = new WorkPackage(wpViewModel, parentWpId, projectId);

            wp.WorkPackageId = wpId; //id is needed for PUT

            await _workPackageRepository.Update(wp);

            //Get and delete existing assignments
            IEnumerable <EmployeeWorkPackageAssignment> empWpList = await _empWorkPackageAssignmentRepository.GetAll();

            foreach (EmployeeNameViewModel emp in wpViewModel.Employees)
            {
                var tempList = empWpList.Where(x => x.EmployeeId == emp.EmployeeId);
                foreach (var empWp in tempList)
                {
                    await _empWorkPackageAssignmentRepository.Delete(empWp);
                }
            }

            await _empWorkPackageAssignmentRepository.Delete(empWpList.FirstOrDefault(x =>
                                                                                      x.EmployeeId == wpViewModel.ResponsibleEngineer.EmployeeId));

            //add updated assignments back
            foreach (EmployeeNameViewModel emp in wpViewModel.Employees)
            {
                EmployeeWorkPackageAssignment empWpAss = new EmployeeWorkPackageAssignment(emp.EmployeeId, wpId);
                await _empWorkPackageAssignmentRepository.Add(empWpAss);
            }

            //add updated RE to db
            EmployeeWorkPackageAssignment re = new EmployeeWorkPackageAssignment(wpViewModel.ResponsibleEngineer.EmployeeId, wpId);
            await _empWorkPackageAssignmentRepository.Add(re);

            //update pmViewModels
            foreach (PmPlanningViewModel pmViewModel in wpViewModel.PmPlannings)
            {
                WorkPackageLabourGradeAssignment wplga = new WorkPackageLabourGradeAssignment(wpId, pmViewModel);
                await _workPackageLabourGradeRepository.Update(wplga);
            }

            return(Ok(200));
        }
Example #2
0
 //For Post. Id is auto generated.
 public WorkPackage(WorkPackageViewModel workPackageViewModel, int parentWpId, int projectId)  //stopped here.  Add constructor, then go back to WorkPackageController.
 //Break down into new WorkPackageLabourGradeAssignment, etc
 {
     this.WorkPackageCode       = workPackageViewModel.WorkPackageCode;
     this.Name                  = workPackageViewModel.WorkPackageTitle;
     this.ResponsibleEngineerId = workPackageViewModel.ResponsibleEngineer.EmployeeId;
     this.ParentWorkPackageId   = parentWpId;
     this.ProjectId             = projectId;
     this.Contractor            = workPackageViewModel.Contractor;
     this.Description           = "No description in new format";
     this.IssueDate             = workPackageViewModel.IssueDate;
     this.IsClosed              = workPackageViewModel.IsClosed;
     this.LastUpdatedTime       = DateTime.Now;
     this.LastUpdatedBy         = Environment.UserName;
 }
Example #3
0
        public async Task <ActionResult <WorkPackageViewModel> > PostWorkPackage(WorkPackageViewModel wpViewModel)
        {
            //Get Project and ParentWpIds
            int parentWpId = _workPackageRepository.GetIdByCode(wpViewModel.ParentWorkPackageCode);
            int projectId  = _projectRepository.GetIdByCode(wpViewModel.ProjectCode);

            WorkPackage wp = new WorkPackage(wpViewModel, parentWpId, projectId);
            await _workPackageRepository.Add(wp);

            //Get id of the wp just added
            int wpId = _workPackageRepository.GetIdByCode(wpViewModel.WorkPackageCode);

            foreach (PmPlanningViewModel pmViewModel in wpViewModel.PmPlannings)
            {
                WorkPackageLabourGradeAssignment wplga = new WorkPackageLabourGradeAssignment(wpId, pmViewModel);
                await _workPackageLabourGradeRepository.Add(wplga);
            }

            return(Ok(wpViewModel));
        }
Example #4
0
        public async Task <IActionResult> PutWorkPackage(int id, WorkPackageViewModel wpViewModel)
        {
            //Get Project and ParentWpIds
            int parentWpId = _workPackageRepository.GetIdByCode(wpViewModel.ParentWorkPackageCode);
            int projectId  = _projectRepository.GetIdByCode(wpViewModel.ProjectCode);
            int wpId       = wpViewModel.WorkPackageId;

            WorkPackage wp = new WorkPackage(wpViewModel, parentWpId, projectId);

            wp.WorkPackageId = wpId; //id is needed for PUT

            await _workPackageRepository.Update(wp);

            foreach (PmPlanningViewModel pmViewModel in wpViewModel.PmPlannings)
            {
                WorkPackageLabourGradeAssignment wplga = new WorkPackageLabourGradeAssignment(wpId, pmViewModel);
                await _workPackageLabourGradeRepository.Update(wplga);
            }

            return(Ok(200));
        }
Example #5
0
        public async Task <ActionResult <WorkPackageViewModel> > PostWorkPackage(WorkPackageViewModel wpViewModel)
        {
            //Get Project and ParentWpIds
            int?parentWpId = null;

            if (wpViewModel.ParentWorkPackageCode != null)
            {
                parentWpId = _workPackageRepository.GetIdByCode(wpViewModel.ParentWorkPackageCode);
            }
            int projectId = _projectRepository.GetIdByCode(wpViewModel.ProjectCode);

            WorkPackage wp = new WorkPackage(wpViewModel, parentWpId, projectId);
            await _workPackageRepository.Add(wp);

            //Get id of the wp just added
            int wpId = _workPackageRepository.GetIdByCode(wpViewModel.WorkPackageCode);

            //add pmViewModels
            foreach (PmPlanningViewModel pmViewModel in wpViewModel.PmPlannings)
            {
                WorkPackageLabourGradeAssignment wplga = new WorkPackageLabourGradeAssignment(wpId, pmViewModel);
                await _workPackageLabourGradeRepository.Add(wplga);
            }

            foreach (EmployeeNameViewModel emp in wpViewModel.Employees)
            {
                EmployeeWorkPackageAssignment empWpAss = new EmployeeWorkPackageAssignment(emp.EmployeeId, wpId);
                await _empWorkPackageAssignmentRepository.Add(empWpAss);
            }

            //add RE to db
            EmployeeWorkPackageAssignment re = new EmployeeWorkPackageAssignment(wpViewModel.ResponsibleEngineer.EmployeeId, wpId);
            await _empWorkPackageAssignmentRepository.Add(re);

            return(Ok(wpViewModel));
        }
Example #6
0
        public async Task <ActionResult <WorkPackage> > GetWorkPackage(string code)
        {
            //Get WpId from param that is WpCode
            int id = _workPackageRepository.GetIdByCode(code);

            //Get WP
            WorkPackage wp = await _workPackageRepository.Get(id);

            //Get ParentWPCode
            int?        parentWpId   = wp.ParentWorkPackageId;
            string      parentWpCode = null;
            WorkPackage parentWp;

            if (parentWpId != null)
            {
                parentWp = await _workPackageRepository.Get((int)parentWpId);

                parentWpCode = parentWp.WorkPackageCode;
            }

            //GetProject
            Project proj = await _projectRepository.Get(wp.ProjectId);

            //Filter EmployeeWokPackageAssignments
            IEnumerable <EmployeeWorkPackageAssignment> empWpAssignments = await _empWorkPackageAssignmentRepository.GetAll();

            empWpAssignments = empWpAssignments.Where(x => x.WorkPackageId == id);

            //Get employees list and Responsible Engineer
            IList <EmployeeNameViewModel> employees           = new List <EmployeeNameViewModel>();
            EmployeeNameViewModel         responsibleEngineer = null;

            foreach (EmployeeWorkPackageAssignment empWpAssignment in empWpAssignments)
            {
                Employee emp = await _employeeRepository.Get(empWpAssignment.EmployeeId);

                if (wp.ResponsibleEngineerId != empWpAssignment.EmployeeId)
                {
                    employees.Add(new EmployeeNameViewModel(emp));
                }
                else
                {
                    responsibleEngineer = new EmployeeNameViewModel(emp);
                }
            }

            //Filter WorkPackageLabourGradeAssignments
            IEnumerable <WorkPackageLabourGradeAssignment> wpLabourGradeAssignments =
                await _workPackageLabourGradeRepository.GetAll();

            wpLabourGradeAssignments = wpLabourGradeAssignments.Where(x => x.WorkPackageId == id);

            //Get PmPlannings
            IList <PmPlanningViewModel> pmPlannings = new List <PmPlanningViewModel>();

            foreach (WorkPackageLabourGradeAssignment item in wpLabourGradeAssignments)
            {
                pmPlannings.Add(new PmPlanningViewModel(item));
            }

            //Create the viewmodel
            WorkPackageViewModel wpViewModel = new WorkPackageViewModel(wp, parentWpCode, proj, responsibleEngineer, employees, pmPlannings);

            // return Ok(await _workPackageRepository.Get(id));  //this is just plain database table object
            return(Ok(wpViewModel));
        }