public DepartmentDocumentDto UpdateDepartmentDocument(long departmentDocumentNumber, DepartmentDocumentRequest departmentDocumentRequest)
        {
            DepartmentDocument departmentDocumentEntity = _departmentDocumentRepository.GetByIdAsync(departmentDocumentNumber).Result;

            _mapper.Map(departmentDocumentRequest, departmentDocumentEntity);

            _departmentDocumentRepository.UpdateAsync(departmentDocumentEntity).Wait();

            return(_mapper.Map <DepartmentDocumentDto>(departmentDocumentEntity));
        }
Exemple #2
0
        public async Task <ActionResult <DepartmentDocument> > Create(int companyId, [FromBody] DepartmentDocument department)
        {
            var companyDto = await CompanyService.GetByIdAsync(companyId);

            if (companyDto == null)
            {
                return(NotFound($"Company with id: '{companyId}' not found"));
            }

            var createdDepartment = await DepartmentService.CreateAsync(companyId, department.ToDto());

            return(CreatedAtAction(nameof(GetById), new { id = createdDepartment.Id }, createdDepartment.ToDocument()));
        }
        public bool DeleteDepartmentDocument(long departmentDocumentNumber)
        {
            DepartmentDocument departmentDocumentEntity = _departmentDocumentRepository.GetByIdAsync(departmentDocumentNumber).Result;

            if (departmentDocumentEntity != null)
            {
                _departmentDocumentRepository.DeleteAsync(departmentDocumentEntity).Wait();
            }
            else
            {
                return(false);
            }

            return(true);
        }
 public static DepartmentDto ToDto(this DepartmentDocument companyDocument) =>
 new DepartmentDto
 {
     Id   = companyDocument.Id,
     Name = companyDocument.Name
 };