Пример #1
0
        public async Task <ActionResult <BusinessLicence> > CreateBusinessLicence(int siteId, BusinessLicence businessLicence, [FromQuery] Guid documentGuid)
        {
            var site = await _siteService.GetSiteAsync(siteId);

            if (site == null)
            {
                return(NotFound(ApiResponse.Message($"Site not found with id {siteId}")));
            }
            if (!site.Provisioner.PermissionsRecord().EditableBy(User))
            {
                return(Forbid());
            }
            if (site.BusinessLicence != null)
            {
                return(Conflict(ApiResponse.Message($"Business Licence exists for site with id {siteId}")));
            }

            var licence = await _siteService.AddBusinessLicenceAsync(siteId, businessLicence, documentGuid);

            if (licence == null)
            {
                ModelState.AddModelError("documentGuid", "Business Licence could not be created; network error or upload is already submitted");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }

            return(Ok(ApiResponse.Result(licence)));
        }
Пример #2
0
        public async Task <ActionResult <BusinessLicence> > CreateBusinessLicence(int siteId, [FromQuery] Guid documentGuid, [FromQuery] string filename)
        {
            var site = await _siteService.GetSiteAsync(siteId);

            if (site == null)
            {
                return(NotFound(ApiResponse.Message($"Site not found with id {siteId}")));
            }

            if (!User.CanEdit(site.Provisioner))
            {
                return(Forbid());
            }

            var licence = await _siteService.AddBusinessLicenceAsync(site.Id, documentGuid, filename);

            // TODO updated to be licence instead of site, and should have GET and CreatedAtAction
            return(Ok(ApiResponse.Result(licence)));
            // return CreatedAtAction(
            //     nameof(GetSiteById),
            //     new { siteId = createdSiteId },
            //     ApiResponse.Result(createdSite)
            // );
        }