Example #1
0
 private static SectionTraffic ConvertToSectionTraffic(UpdateSectionTrafficCommand command)
 {
     return(new SectionTraffic
     {
         SectionId = command.SectionId,
         DataVersionId = command.DataVersionId,
         BLDate = command.BLDate,
         BLReference = command.BLReference,
         VesselCode = string.IsNullOrEmpty(command.VesselCode) ? null : command.VesselCode,
         ShippingStatusCode = string.IsNullOrEmpty(command.ShippingStatusCode) ? null : command.ShippingStatusCode,
     });
 }
Example #2
0
        public async Task <Unit> Handle(UpdateSectionTrafficCommand request, CancellationToken cancellationToken)
        {
            _unitOfWork.BeginTransaction();

            try
            {
                var sectionTraffic = ConvertToSectionTraffic(request);

                var authorizationResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), sectionTraffic, Policies.CharterPolicy);

                var vesselNamePolicyResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), sectionTraffic, Policies.VesselNamePolicy);

                var blDatePolicyResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), sectionTraffic, Policies.BlDatePolicy);

                var blReferencePolicyResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), sectionTraffic, Policies.BlReferencePolicy);

                var quantityForTrafficPolicyResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), sectionTraffic, Policies.QuantityForTrafficPolicy);

                if (authorizationResult.Succeeded || vesselNamePolicyResult.Succeeded || blDatePolicyResult.Succeeded || blReferencePolicyResult.Succeeded || quantityForTrafficPolicyResult.Succeeded)
                {
                    if (request.DataVersionId != null)
                    {
                        var freezeDate = await _freezeRepository.GetFreezeNotClosedAsync(request.CompanyId, request.DataVersionId.Value);

                        if (freezeDate == null)
                        {
                            throw new AtlasBusinessException($"Contracts cannot be updated in a freeze if the month is closed.");
                        }
                    }

                    var companyDate = await _systemDateTimeService.GetCompanyDate(request.CompanyId);

                    if (request.BLDate != null && request.BLDate.Value.Date > companyDate.Date)
                    {
                        throw new AtlasBusinessException($"BL Date cannot be in the future. Bl Date: {request.BLDate.Value.Date}. Company date: {companyDate}.");
                    }

                    await _charterRepository.UpdateSectionTrafficDetailsAsync(sectionTraffic, request.CompanyId, request.DataVersionId);

                    if (request.DataVersionId != null)
                    {
                        await InsertFreezeRecalcProcessQueue(request.SectionId, request.DataVersionId, request.CompanyId);
                    }

                    _unitOfWork.Commit();

                    _logger.LogInformation("Section Traffic with id {Atlas_SectionId} updated.", request.SectionId);
                }
                else
                {
                    throw new AtlasSecurityException("One or more privileges are required to perform this action.");
                }

                return(Unit.Value);
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }