Exemple #1
0
        public bool IsValidPortForCategory(int categoryCode, string reportingPort, string associatedPort, bool?InBound)
        {
            var allowedCat = true;

            switch (categoryCode)
            {
            case 12:
            {
                allowedCat = _portFreightContext.PortCargoOil.AsQueryable().AsNoTracking()
                             .Where(a => a.Locode == _helperService.GetPortCodeByPort(reportingPort))
                             .Select(a => a.AllowCategory12).SingleOrDefault();
            }
            break;

            case 13:
            {
                if (InBound == true)
                {
                    var gbPort = _helperService.GetCountryCodeByPort(associatedPort);
                    allowedCat = gbPort != null && gbPort.Equals("GB") ? IsAllowedPort(associatedPort) : true;
                }
                else
                {
                    allowedCat = IsAllowedPort(reportingPort);
                }
            }
            break;

            default:
            {
            }
            break;
            }
            return(allowedCat);
        }
        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 async Task IsValidPort_Whentrue_ShouldReturnValidPortCode()
        {
            string portCodeGB = "GBABD";
            string portCodeAU = "AU888";
            string portNameGB = "Aberdeen / UNITED KINGDOM (GBABD)";
            string portNameAU = "AUSTRALIA - Not Specified / AUSTRALIA (AU888)";

            var globalPort = new List <GlobalPort>()
            {
                new GlobalPort {
                    Locode      = portCodeGB,
                    PortName    = portNameGB,
                    CountryCode = "GB"
                },

                new GlobalPort {
                    Locode      = portCodeAU,
                    PortName    = portNameAU,
                    CountryCode = "AU"
                }
            };
            await actualContext.GlobalPort.AddRangeAsync(globalPort);

            actualContext.SaveChanges();

            var result   = _helperService.GetPortCodeByPort(portNameGB);
            var category = globalPort.Find(x => x.PortName == portNameGB).Locode;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.IsNotNull(category);
            Assert.AreEqual(result, category);
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync(string locode)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Input.SenderPortLocode = locode;
            if (Input.SenderPortLocode == null)
            {
                ModelState.AddModelError("Input.SenderPortLocode", "Enter the port name or locode that you report data for");
            }
            var portLocode = _helperService.GetPortCodeByPort(locode);

            if (portLocode == null)
            {
                ModelState.AddModelError("Input.SenderPortLocode", "Enter a valid port name or locode that you report data for");
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (_context.SenderIdPort.Where(p => p.Locode == portLocode && p.SenderId == user.SenderId).Count() > 0)
            {
                ModelState.AddModelError("Input.SenderPortLocode", "Port is already in the list");
            }

            if (ModelState.IsValid)
            {
                var senderIdPort = new SenderIdPort
                {
                    Locode   = portLocode,
                    SenderId = user.SenderId
                };

                _context.SenderIdPort.Add(senderIdPort);
                await _context.SaveChangesAsync();

                SuccessMessage = "Port successfully saved";
            }

            InitialisePage(user);

            return(Page());
        }