コード例 #1
0
        public async Task <ResultData <EmployeeRelocateModel> > CreateRelocateModel(int id)
        {
            if (id == 0)
            {
                return(new ResultData <EmployeeRelocateModel>(EmployeeNotFoundMessage, false, null));
            }

            Employee employee = await this.employeeRepository.GetEmployeeById(id);

            Office office = await this.officeRepository.GetOfficeById(employee.OfficeId);

            Company company = await this.companyRepository.GetCompanyWithOfficesById(office.CompanyId);

            EmployeeRelocateModel model = new EmployeeRelocateModel
            {
                Id             = employee.Id,
                FullName       = $"{employee.FirstName} {employee.LastName}",
                CompanyOffices = company.Offices.Select(o => new RelocateEmployeeOfficeModel
                {
                    Id      = o.Id,
                    Address = $"{o.StreetNumber} {o.Street}, {o.City}, {o.Country}"
                })
            };

            return(new ResultData <EmployeeRelocateModel>(EmployeeRelocateModelCreatedMessage, true, model));
        }
コード例 #2
0
        public async Task <ResultData <Employee> > RelocateEmployee(EmployeeRelocateModel inputModel)
        {
            if (inputModel.NewOfficeId == 0)
            {
                return(new ResultData <Employee>(OfficeNotFoundMessage, false, null));
            }

            Employee employee = await this.employeeRepository.GetEmployeeById(inputModel.Id);

            employee.OfficeId = inputModel.NewOfficeId;

            await this.employeeRepository.EditEmployee(employee);

            return(new ResultData <Employee>(EmployeeUpdatedMessage, true, employee));
        }
コード例 #3
0
        public async Task <IActionResult> Relocate(EmployeeRelocateModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var result = await this.employeeService.RelocateEmployee(inputModel);

            if (!result.Success)
            {
                return(this.View(inputModel));
            }

            return(this.RedirectToAction("Details", "Offices", new { id = result.Data.OfficeId }));
        }