public async Task <IActionResult> UpdateEmployee(int id, StaffForEditDto employeeForEditDto)
        {
            // if(id!= int.Parse(Employee.FindFirst(ClaimTypes.NameIdentifier).Value))
            //     return Unahthrized();
            var employeeFromRepo = await _repo.GetEmployee(id);

            _mapper.Map(employeeForEditDto, employeeFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"Updating employee {id} failed on save");
        }
Exemple #2
0
        public async Task <ActionResult <StaffDto> > EditStaff([FromRoute] int staffId,
                                                               [FromBody] StaffForEditDto staff)
        {
            var staffEntityToEdit = await _staffRepo.GetStaffByIdAsync(staffId);

            if (staffEntityToEdit == null)
            {
                return(NotFound());
            }
            _mapper.Map(staff, staffEntityToEdit);
            _staffRepo.UpdateStaff(staffEntityToEdit);
            await _staffRepo.SaveAsync();

            return(Ok(_mapper.Map <StaffDto>(staffEntityToEdit)));
        }