private MSD1 mapMSD1DataToMSD1(string Id)
        {
            Msd1Data msd1Data = _context.Msd1Data.First(x => x.Msd1Id == Id) ?? new Msd1Data();

            MSD1 msd1 = new MSD1()
            {
                Imo            = msd1Data.Imo,
                ShipName       = msd1Data.ShipName ?? _helperService.GetShipNameByIMO(msd1Data.Imo),
                Deadweight     = _helperService.GetDeadweightByIMO(msd1Data.Imo),
                Year           = msd1Data.Year,
                Quarter        = msd1Data.Quarter,
                AssociatedPort = _helperService.GetPortNameByCode(msd1Data.AssociatedPort)
                                 ?? msd1Data.AssociatedPort,
                ReportingPort = _helperService.GetPortNameByCode(msd1Data.ReportingPort)
                                ?? msd1Data.ReportingPort,
                NumVoyages       = msd1Data.NumVoyages,
                IsInbound        = msd1Data.IsInbound,
                Msd1Id           = msd1Data.Msd1Id,
                AgentSenderID    = msd1Data.AgentSenderId,
                AgentCompanyName = _helperService.GetCompanyNameBySenderID(msd1Data.AgentSenderId) ?? string.Empty,
                LineSenderID     = msd1Data.LineSenderId,
                LineCompanyName  = _helperService.GetCompanyNameBySenderID(msd1Data.LineSenderId) ?? string.Empty,
                FlagCode         = _helperService.GetFlagCodeFromIMO(msd1Data.Imo) ?? string.Empty,
                RecordRef        = msd1Data.RecordRef,
                CargoSummary     = MapMsd1CargoSummaryToCargoItem(msd1Data.Msd1Id)
            };

            return(msd1);
        }
        private async Task UpdateLastUpdatedAsync()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            Msd = _context.Msd1Data.Where(x => x.Msd1Id == TempData.Peek("Msd1Id").ToString()).First();
            Msd.ModifiedDate  = DateTime.Now;
            Msd.LastUpdatedBy = user.UserName;
        }
 public void Add(Msd1Data msd1)
 {
     if (msd1 != null)
     {
         _context.Msd1Data.Add(msd1);
         _context.SaveChanges();
         _context.Entry(msd1).State = EntityState.Detached;
     }
 }
Exemplo n.º 4
0
        public IActionResult OnGet()
        {
            try
            {
                msd1      = TempData.GetKeep <Msd1Data>("Msd1");
                IsInbound = msd1.IsInbound;
            }
            catch
            {
                return(Page());
            }

            return(Page());
        }
        private void MapMsd1ToMsd1Data()
        {
            Msd1Data = _context.Msd1Data.FirstOrDefault(x => x.Msd1Id == MSD1.Msd1Id) ?? new Msd1Data();

            Msd1Data.Msd1Id         = MSD1.Msd1Id ?? _helperService.GetUniqueKey();
            Msd1Data.Imo            = MSD1.Imo;
            Msd1Data.ShipName       = MSD1.ShipName;
            Msd1Data.FlagCode       = MSD1.FlagCode;
            Msd1Data.Year           = MSD1.Year;
            Msd1Data.Quarter        = MSD1.Quarter;
            Msd1Data.AssociatedPort = _helperService.GetPortCodeByPort(MSD1.AssociatedPort) ?? MSD1.AssociatedPort;
            Msd1Data.ReportingPort  = _helperService.GetPortCodeByPort(MSD1.ReportingPort) ?? MSD1.ReportingPort;
            Msd1Data.NumVoyages     = MSD1.NumVoyages;
            Msd1Data.IsInbound      = MSD1.IsInbound == null ? false : MSD1.IsInbound.Value;
            Msd1Data.VoyageDate     = MSD1.VoyageDate;
            Msd1Data.UserName       = Msd1Data.UserName ?? _userManager.GetUserName(HttpContext.User);
            Msd1Data.DataSourceId   = (int)DataSource.WEB;
            Msd1Data.CreatedDate    = Msd1Data.CreatedDate != default(DateTime) && Msd1Data.CreatedDate < DateTime.Now ?
                                      Msd1Data.CreatedDate : DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc);
            Msd1Data.LastUpdatedBy = _userManager.GetUserName(HttpContext.User);
            Msd1Data.ModifiedDate  = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc);
            Msd1Data.AgentSenderId = MSD1.AgentSenderID;
            Msd1Data.LineSenderId  = MSD1.LineSenderID;
            Msd1Data.RecordRef     = MSD1.RecordRef;

            Msd1Data.Msd1CargoSummary = _context.Msd1CargoSummary.Where(x => x.Msd1Id == Msd1Data.Msd1Id)
                                        .ToList();

            if (Msd1Data.Msd1CargoSummary.Count > 0)
            {
                Msd1Data.Msd1CargoSummary.Clear();
            }

            foreach (CargoItem item in MSD1.CargoSummary)
            {
                Msd1CargoSummary msd1CargoSummary = new Msd1CargoSummary
                {
                    Msd1Id            = Msd1Data.Msd1Id,
                    CategoryCode      = _helperService.GetCategoryCodeByDescription(item.Category),
                    UnitsWithCargo    = item.UnitsWithCargo,
                    UnitsWithoutCargo = item.UnitsWithoutCargo,
                    TotalUnits        = item.TotalUnits,
                    GrossWeight       = (decimal?)item.GrossWeight,
                    Description       = item.Description
                };

                Msd1Data.Msd1CargoSummary.Add(msd1CargoSummary);
            }
            ;
        }
        public void mapInputsToMSDI(PortFreightUser user)
        {
            msd1 = TempData.GetKeep <Msd1Data>("Msd1");

            msd1.Imo            = Imo;
            msd1.ShipName       = ShipName;
            msd1.Year           = Year;
            msd1.Quarter        = Quarter;
            msd1.NumVoyages     = NumVoyages;
            msd1.ReportingPort  = ReportingPort;
            msd1.AssociatedPort = AssociatedPort;
            msd1.LastUpdatedBy  = user.Email;
            msd1.ModifiedDate   = DateTime.Now;
            msd1.IsInbound      = IsInbound;
        }
        public (bool, string) ValidateMSd1CargoSummary(Msd1Data msd1Data, Msd1CargoSummary cargoItem)
        {
            sb = new StringBuilder();
            var modelState = _cargoPortValidateService.ManualModelCargoValidation(msd1Data, cargoItem);

            if (modelState.IsValid)
            {
                return(true, string.Empty);
            }
            foreach (var error in modelState.Values.SelectMany(item => item.Errors))
            {
                sb.AppendLine().AppendLine(error.ErrorMessage);
            }

            return(false, sb.ToString());
        }
        public IActionResult OnGet()
        {
            try
            {
                CargoSummary = _context.Msd1CargoSummary.Where(x => x.Id == int.Parse(TempData.Peek("SumId").ToString()))
                               .First();

                Msd = _context.Msd1Data.Where(x => x.Msd1Id == TempData.Peek("Msd1Id").ToString()).First();
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(RedirectToPage("/Index", new { area = "Admin" }));
            }

            return(Page());
        }
        public FileProcessing(FlatFile flatFile,
                              Msd1Data msd1Data,
                              EmailNotification emailNotification,
                              IFileProcessService fileProcessService,
                              IMsd1DataService msd1DataService,
                              ILogger <FileProcessing> logger,
                              ASCIIFileProcess asciiFileProcess,
                              IOptions <FileOptions> settings,
                              GESMESFileProcess gesmesFileProcess

                              )
        {
            _logger            = logger;
            _asciiFileProcess  = asciiFileProcess;
            _settings          = settings.Value;
            _gesmesFileProcess = gesmesFileProcess;
            _emailNotification = emailNotification;
        }
Exemplo n.º 10
0
 public Msd1FileProcess(Msd1Data msd1,
                        FlatFile fileInfo,
                        GesmesHelpers gesmesHelpers,
                        ValidateMsdData validateMsdData,
                        IMsd1DataService msd1DataService,
                        IFileProcessService fileProcessService,
                        IHelperService helperService,
                        ILogger <Msd1FileProcess> logger)
 {
     _msd1               = msd1;
     _fileInfo           = fileInfo;
     _gesmesHelpers      = gesmesHelpers;
     _helperService      = helperService;
     _msd1DataService    = msd1DataService;
     _validateMsdData    = validateMsdData;
     _fileProcessService = fileProcessService;
     _logger             = logger;
     recordErrors        = new StringBuilder();
     bodyErrorMsg        = new StringBuilder();
 }
Exemplo n.º 11
0
        public MSD1FileProcess(Msd1Data msd1,
                               Msd1CargoSummary msd1CargoSummary,
                               FlatFile fileInfo,
                               ValidateMsdData validateMsdData,
                               IHelperService helperService,
                               IFileProcessService fileProcessService,
                               IMsd1DataService msd1DataService,
                               ILogger <MSD1FileProcess> logger

                               )
        {
            _msd1               = msd1;
            _msd1CargoSummary   = msd1CargoSummary;
            _fileInfo           = fileInfo;
            _helperService      = helperService;
            _fileProcessService = fileProcessService;
            _msd1DataService    = msd1DataService;
            _logger             = logger;
            _validateMsdData    = validateMsdData;
            recordErrors        = new StringBuilder();
            bodyErrorMsg        = new StringBuilder();
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            try
            {
                Msd1Data ToRemove = _context.Msd1Data.FirstOrDefault(x => x.Msd1Id == id);

                _context.Msd1Data.Remove(ToRemove);

                _context.SaveChanges();

                TempData.Put("DeleteSuccess", "Submission has been succesfully deleted");

                return(RedirectToPage("/Submissions/FindSubmission", new { area = "Admin" }));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", "There has been an error connecting to the database");
                _logger.LogError(e.Message);
            }

            return(Page());
        }
Exemplo n.º 13
0
        public ModelStateDictionary ManualModelCargoValidation(Msd1Data localMSD1, Msd1CargoSummary cargoItem)
        {
            totalGrossWeight = 0;

            _modelState = new ModelStateDictionary();

            var currentCargoGroup = _portFreightContext.CargoGroup.
                                    Join(_portFreightContext.CargoCategory, cg => cg.GroupCode, cc => cc.GroupCode,
                                         (cg, cc) => new { cg, cc })
                                    .Where(x => x.cc.CategoryCode.Equals(cargoItem.CategoryCode))
                                    .Select(x => x.cg).FirstOrDefault();

            if (currentCargoGroup == null)
            {
                _modelState.AddModelError("CargoItem.CategoryCode", "Invalid value for category code. Please correct or contact the helpdesk for advice.");
                return(_modelState);
            }

            var cargoCategory        = _portFreightContext.CargoCategory.Where(x => x.GroupCode == currentCargoGroup.GroupCode);
            var currentCargoCategory = cargoCategory.FirstOrDefault(x => x.CategoryCode == cargoItem.CategoryCode);

            TextInputDisplayDriver = BuildTextInputDisplayDriver(currentCargoCategory, currentCargoGroup.IsUnitised);

            var grossWeightVisible          = TextInputDisplayDriver.Contains(WeightConfigure);
            var numUnitsVisible             = TextInputDisplayDriver.Contains(NoCargoConfigure);
            var numUnitsWithCargoVisible    = TextInputDisplayDriver.Contains(CargoConfigure) && !numUnitsVisible;
            var numUnitsWithoutCargoVisible = numUnitsWithCargoVisible;

            if (numUnitsVisible && (!cargoItem.TotalUnits.HasValue || cargoItem.TotalUnits == 0))
            {
                _modelState.AddModelError("CargoItem.TotalUnits", "Missing value for total units. Please correct or contact the helpdesk for advice.");
            }

            if (numUnitsWithCargoVisible && (!cargoItem.UnitsWithCargo.HasValue))
            {
                _modelState.AddModelError("CargoItem.UnitsWithCargo", "Invalid value for units with cargo. Please correct or contact the helpdesk for advice.");
            }

            if (numUnitsWithoutCargoVisible && (!cargoItem.UnitsWithoutCargo.HasValue))
            {
                _modelState.AddModelError("CargoItem.UnitsWithoutCargo", "Invalid value for units without cargo. Please correct or contact the helpdesk for advice.");
            }

            if (grossWeightVisible)
            {
                if (!cargoItem.GrossWeight.HasValue)
                {
                    _modelState.AddModelError("CargoItem.GrossWeight", "Invalid value for gross weight. Please correct or contact the helpdesk for advice.");
                }
                else if (!numUnitsWithCargoVisible && !numUnitsWithoutCargoVisible && cargoItem.GrossWeight == 0)
                {
                    _modelState.AddModelError("CargoItem.GrossWeight", "Gross weight cannot be 0. Please correct or contact the helpdesk for advice.");
                }
            }

            if (numUnitsWithCargoVisible &&
                numUnitsWithoutCargoVisible &&
                cargoItem.UnitsWithCargo == 0 &&
                cargoItem.UnitsWithoutCargo == 0)
            {
                _modelState.AddModelError("CargoItem.UnitsWithCargo", "Number of units with and without cargo cannot both be 0. Please correct or contact the helpdesk for advice.");
            }

            if (numUnitsWithCargoVisible && cargoItem.UnitsWithCargo > 0 && cargoItem.GrossWeight == 0)
            {
                _modelState.AddModelError("CargoItem.GrossWeight",
                                          "You reported " + cargoItem.UnitsWithCargo + " units with cargo but no weight. Enter the weight of this cargo or contact the helpdesk for advice.");
            }

            if (numUnitsWithCargoVisible && cargoItem.UnitsWithCargo == 0 && cargoItem.GrossWeight > 0)
            {
                _modelState.AddModelError("CargoItem.UnitsWithCargo",
                                          "You reported cargo weighing " + cargoItem.GrossWeight + " tonnes. Enter the number of units that were carrying this cargo or contact the helpdesk for advice.");
            }
            return(_modelState);
        }