Exemplo n.º 1
0
        public async Task <EmployeeFullInfo> CreateEmployeeAsync(UpdateEmployeeRequest createRequest)
        {
            var dbEmployee = Mapper.Map <UpdateEmployeeRequest, DbEmployee>(createRequest);

            _context.Employees.Add(dbEmployee);

            await _context.SaveChangesAsync();

            return(Mapper.Map <EmployeeFullInfo>(dbEmployee));
        }
Exemplo n.º 2
0
        public async Task <EmployeeFullInfo> UpdateEmployeeAsync(int employeeId, UpdateEmployeeRequest updateRequest)
        {
            var dbEmployees = await _context.Employees.Where(p => p.Id == employeeId).ToArrayAsync();

            if (dbEmployees.Length == 0)
            {
                throw new RequestedResourceNotFoundException();
            }

            var dbEmployee = dbEmployees[0];

            Mapper.Map(updateRequest, dbEmployee);
            await _context.SaveChangesAsync();

            return(Mapper.Map <EmployeeFullInfo>(dbEmployee));
        }