Ejemplo n.º 1
0
        public async Task <BusinessLicence> UpdateBusinessLicenceAsync(int siteId, BusinessLicence updateBusinessLicence)
        {
            var businessLicence = await _context.BusinessLicences.Where(bl => bl.SiteId == siteId).SingleOrDefaultAsync();

            businessLicence.DeferredLicenceReason = updateBusinessLicence.DeferredLicenceReason;

            _context.BusinessLicences.Update(businessLicence);
            await _context.SaveChangesAsync();

            return(businessLicence);
        }
Ejemplo n.º 2
0
        public async Task <BusinessLicence> AddBusinessLicenceAsync(int siteId, BusinessLicence businessLicence, Guid documentGuid)
        {
            businessLicence.SiteId = siteId;

            if (documentGuid != Guid.Empty)
            {
                businessLicence.BusinessLicenceDocument = await CreateBusinessLicenceDocument(documentGuid);
            }

            _context.BusinessLicences.Add(businessLicence);
            await _context.SaveChangesAsync();

            return(businessLicence);
        }
Ejemplo n.º 3
0
        public async Task <BusinessLicence> AddBusinessLicenceAsync(int siteId, Guid documentGuid, string filename)
        {
            var businessLicence = new BusinessLicence
            {
                DocumentGuid = documentGuid,
                SiteId       = siteId,
                FileName     = filename,
                UploadedDate = DateTimeOffset.Now
            };

            _context.BusinessLicences.Add(businessLicence);

            var updated = await _context.SaveChangesAsync();

            if (updated < 1)
            {
                throw new InvalidOperationException($"Could not add business licence.");
            }

            return(businessLicence);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <BusinessLicence> > UpdateBusinessLicence(int siteId, BusinessLicence businessLicence)
        {
            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.BusinessLicenceDocument != null)
            {
                return(Conflict(ApiResponse.Message($"Business licence already uploaded, update not allowed.")));
            }

            var licence = await _siteService.UpdateBusinessLicenceAsync(site.Id, businessLicence);

            return(Ok(ApiResponse.Result(licence)));
        }
Ejemplo n.º 5
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)));
        }