Esempio n. 1
0
        public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            EmployeeDetailsServiceModel employee = await this._employeeServices.GetEmployeeByIdAsync(id);

            if (employee == null)
            {
                return(NotFound());
            }

            EmployeeEditBindingModel model = new EmployeeEditBindingModel()
            {
                Id               = employee.EmployeeId,
                FirstName        = employee.FirstName,
                LastName         = employee.LastName,
                StartingDate     = employee.StartingDate,
                Salary           = employee.Salary,
                ExperienceLevel  = employee.ExperienceLevel,
                VacationDays     = employee.VacationDays,
                EmployeesOffices = employee.EmployeesOffices
            };

            return(View(model));
        }
Esempio n. 2
0
        public async Task <ActionResult> GetByIdAsync(int id)
        {
            EmployeeDetailsServiceModel employee =
                await employeesService.GetByIdAsync(id);

            if (employee == null)
            {
                return(NotFound());
            }

            return(Ok(employee));
        }
Esempio n. 3
0
        public async Task <EmployeeDetailsServiceModel> GetByIdAsync(int id)
        {
            EmployeeDetailsServiceModel employee = await dbContext
                                                   .Employees
                                                   .Where(e => e.Id == id)
                                                   .Select(e => new EmployeeDetailsServiceModel
            {
                Id              = e.Id,
                FirstName       = e.FirstName,
                LastName        = e.LastName,
                Salary          = e.Salary,
                ExperienceLevel = e.ExperienceLevel.ToString(),
                StartingDate    = e.StartingDate,
                VacationDays    = e.VacationDays,
                Image           = e.Image
            })
                                                   .FirstOrDefaultAsync();

            return(employee);
        }
Esempio n. 4
0
        public async Task <EmployeeDetailsServiceModel> GetEmployeeByIdAsync(string id)
        {
            Employee employee = await this._context.Employees
                                .Include(eo => eo.EmployeesOffices)
                                .ThenInclude(o => o.Office)
                                .FirstOrDefaultAsync(e => e.EmployeeId == id);

            IEnumerable <string> officesKeys = employee.EmployeesOffices.Select(x => x.OfficeId).ToList();

            List <Office> offices = this._context.Offices
                                    .Where(x => officesKeys.Contains(x.OfficeId))
                                    .ToList();

            List <OfficeDetailsServiceModel> officeDetailServiceModelCollection = offices.Select(o => new OfficeDetailsServiceModel
            {
                City         = o.City,
                Country      = o.Country,
                OfficeId     = o.OfficeId,
                Street       = o.Street,
                StreetNumber = o.StreetNumber,
                IsHQ         = o.IsHQ
            })
                                                                                  .ToList();

            EmployeeDetailsServiceModel serviceModel = new EmployeeDetailsServiceModel()
            {
                EmployeeId       = employee.EmployeeId,
                FirstName        = employee.FirstName,
                LastName         = employee.LastName,
                Salary           = employee.Salary,
                StartingDate     = employee.StartingDate,
                ExperienceLevel  = employee.ExperienceLevel,
                VacationDays     = employee.VacationDays,
                EmployeesOffices = officeDetailServiceModelCollection
            };

            return(serviceModel);
        }