コード例 #1
0
        public async Task <ServiceResponse> SaveProject(ProjectDto ProjectDto)
        {
            ServiceResponse ret = new ServiceResponse();

            // validate
            // save
            if (ProjectDto.Id == Guid.Empty)
            {
                ProjectDto.Id = Guid.NewGuid();
            }

            var existingProject = await this.projectRepository.GetIdByName(ProjectDto.Name);

            if (existingProject != Guid.Empty && ProjectDto.Id == Guid.Empty)
            {
                ret.AddError(new ServiceResponseItem("Name", "Project name already exists!"));
                return(ret.Get());
            }

            if (string.IsNullOrEmpty(ProjectDto.Name))
            {
                ret.Errors.Add(new ServiceResponseItem("Name", "Project name is mandatory!"));
            }

            if (ProjectDto.Customer == null)
            {
                ret.Errors.Add(new ServiceResponseItem("Customer", "Customer is mandatory!"));
                //throw new ArgumentException("Customer is mandatory!");
            }

            Project proj = new Project(ProjectDto.Id, ProjectDto.Name, ProjectDto.DXCServices, ProjectDto.Facts, ProjectDto.DXCSolution, ProjectDto.Betriebsleistung);

            proj.SetCustomer(new Customer(ProjectDto.Customer.Id, ProjectDto.Customer.Name));
            if (ProjectDto.Industry != null)
            {
                proj.SetIndustry(new Industry(ProjectDto.Industry.Id, ProjectDto.Industry.Name));
            }

            foreach (SkillDto s in ProjectDto.Skills)
            {
                proj.AddSkill(new Skill(s.Id, s.Name));
            }
            foreach (RegionDto r in ProjectDto.Regions)
            {
                proj.AddRegion(new Region(r.Id, r.Name, r.KeyNamePath));
            }

            foreach (OfferingDto o in ProjectDto.Offerings)
            {
                proj.AddOffering(new Offering(o.Id, o.Name, o.KeyNamePath));
            }

            await this.projectRepository.SaveProjectAsync(proj);

            //return ServiceResponse.GetOk();
            return(ret);
        }
コード例 #2
0
        public async Task <ServiceResponse> SaveEmployeeAsync(EmployeeDto EmployeeDto)
        {
            ServiceResponse ret = new ServiceResponse();

            Guid newId = Guid.Empty;

            try
            {
                if (EmployeeDto.Id == Guid.Empty)
                {
                    newId          = Guid.NewGuid();
                    EmployeeDto.Id = newId;
                }

                Guid existing_id = await this.employeeRepository.GetIdByName(EmployeeDto.Name);

                // TODO: check everything
                // if new record and name already exists
                if (existing_id != Guid.Empty && existing_id != EmployeeDto.Id)
                {
                    ret.AddError(new ServiceResponseItem("EmployeeName", $"Employe with name: {EmployeeDto.Name} already exists."));
                }

                // WorkPlace
                if (EmployeeDto.WorkPlace.Id == Guid.Empty)
                {
                    ret.AddError(new ServiceResponseItem("WorkPlace", $"Workplace must be defined"));
                }

                // check Manager

                if (EmployeeDto.Manager != null && EmployeeDto.Manager.Id == Guid.Empty)
                {
                    ret.AddError(new ServiceResponseItem("Manager", $"Manager must be defined"));
                }

                if (EmployeeDto.Manager == null)
                {
                    ret.AddError(new ServiceResponseItem("Manager", $"Manager must be defined"));
                }

                if (EmployeeDto.Manager != null)
                {
                    Manager manager = await this.managerRepository.GetById(EmployeeDto.Manager.Id);

                    if (manager == null)
                    {
                        ret.AddError(new ServiceResponseItem("Manager", $"Invalid Manager specified!"));
                    }
                }


                // other checks goes here


                // if any errors, return
                if (ret.HasErrors())
                {
                    return(ret.Get());
                }

                //

                // compose new empoyee
                Employee employee = new Employee(EmployeeDto.Id, EmployeeDto.Name, EmployeeDto.Email);
                if (EmployeeDto.WorkPlace != null)
                {
                    WorkPlaceDto wpDto = EmployeeDto.WorkPlace;
                    WorkPlace    wp    = new WorkPlace(wpDto.Id, wpDto.Country, wpDto.City, wpDto.Name);
                    employee.SetWorkPlace(wp);
                }

                if (EmployeeDto.Manager != null)
                {
                    ManagerDto mDto = EmployeeDto.Manager;
                    employee.SetManager(new Manager(mDto.Id, mDto.Name));
                }

                foreach (EmployeeSkillDto sdto in EmployeeDto.Skills)
                {
                    employee.AddSkill(sdto.Id, sdto.Name, MaturityEnum.High);
                }

                foreach (EmployeeRoleDto rdto in EmployeeDto.Roles)
                {
                    ContributionGroup cg = new ContributionGroup(rdto.ContributionGroup.Id, rdto.ContributionGroup.Name);
                    employee.AddRole(rdto.RoleId, rdto.Name, cg);
                }

                await this.employeeRepository.UpdateEmployeeAsync(employee);
            }
            catch (Exception ex)
            {
                ret.SetErrorMessage("Error while saving an employee occured : " + ex.Message);
            }
            return(ret.Get());
        }