public async Task <IActionResult> AcceptOrganizationAgreement(int organizationId, int agreementId, [FromQuery] Guid?organizationAgreementGuid)
        {
            var organization = await _organizationService.GetOrganizationNoTrackingAsync(organizationId);

            if (organization == null)
            {
                return(NotFound(ApiResponse.Message($"Organization not found with id {organizationId}")));
            }
            if (!organization.SigningAuthority.PermissionsRecord().EditableBy(User))
            {
                return(Forbid());
            }

            if (organizationAgreementGuid.HasValue)
            {
                var signedAgreement = await _organizationService.AddSignedAgreementAsync(organizationId, agreementId, organizationAgreementGuid.Value);

                if (signedAgreement == null)
                {
                    ModelState.AddModelError(nameof(organizationAgreementGuid), "Signed Organization Agreement could not be created; network error or upload is already submitted");
                    return(BadRequest(ApiResponse.BadRequest(ModelState)));
                }
            }

            await _organizationService.AcceptOrgAgreementAsync(organizationId, agreementId);

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <SignedAgreement> > CreateSignedAgreement(int organizationId, [FromQuery] Guid documentGuid, [FromQuery] string filename)
        {
            var organization = await _organizationService.GetOrganizationAsync(organizationId);

            if (organization == null)
            {
                return(NotFound(ApiResponse.Message($"Organization not found with id {organizationId}")));
            }

            if (!User.CanEdit(organization.SigningAuthority))
            {
                return(Forbid());
            }

            var agreement = await _organizationService.AddSignedAgreementAsync(organization.Id, documentGuid, filename);

            return(CreatedAtAction(
                       nameof(GetSignedAgreement),
                       new { organizationId = organization.Id },
                       ApiResponse.Result(agreement)
                       ));
        }