public async Task <IActionResult> Delete(int id)
        {
            var employer = await _employerRepository.GetByIdAsync(id);

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

            await _projectEmployerRepository.RemoveRangeAsync(employer.Projects);

            await _employerRepository.RemoveAsync(employer);

            return(Json(Ok()));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update(int id, [FromBody] ProjectDTO projectDto)
        {
            var sourceProject = await _projectRepository.GetByIdAsync(id, true);

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

            await _projectEmployerRepository.RemoveRangeAsync(sourceProject.Performers);

            sourceProject = _mapper.Map(projectDto, sourceProject);

            Employer projectManager = null;

            if (projectDto.ProjectManagerDtoId != null)
            {
                projectManager = await _employerRepository.GetByIdAsync(projectDto.ProjectManagerDtoId.Id);
            }

            _projectRepository.Update(sourceProject);

            var performersIds = new List <EmployerIdDTO>();

            if (projectDto.PerformersIds.Count != 0)
            {
                performersIds = projectDto.PerformersIds;
            }

            sourceProject.ProjectManager = projectManager;
            _projectModel.UpdatePerformersByListEmployerIdDto(sourceProject, performersIds);

            await _projectRepository.UpdateAsync(sourceProject);

            return(Json(Ok()));
        }