Exemple #1
0
        /// <inheritdoc/>
        public async Task <Employee> CreateEmployeeAsync(UpdateEmployeeRequest createRequest)
        {
            var dbEmployee = Mapper.Map <UpdateEmployeeRequest, DbEmployee>(createRequest);

            _context.Employees.Add(dbEmployee);

            await _context.SaveChangesAsync();

            return(Mapper.Map <Employee>(dbEmployee));
        }
Exemple #2
0
        /// <inheritdoc/>
        public async Task <Employee> UpdateEmployeeAsync(int departmentId, UpdateEmployeeRequest updateRequest)
        {
            var dbEmployees = await _context.Employees.Where(e => e.Id == departmentId).ToArrayAsync();

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

            var dbEmployee = dbEmployees[0];

            Mapper.Map(updateRequest, dbEmployee);

            await _context.SaveChangesAsync();

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