Exemple #1
0
        private void CargoItemValidation(MSD1 localMSD1, CargoCategory currentCargoCategory, CargoGroup currentCargoGroup)
        {
            ManualModelValidation(localMSD1);

            CargoCategoryHardValidations(localMSD1, currentCargoCategory);
            bool selectedCategory12 = currentCargoCategory.CategoryCode == (int)PortCategory.CrudeOilCode;
            bool selectedCategory13 = currentCargoCategory.CategoryCode == (int)PortCategory.OilProductsCode;

            bool isValidCategory = _cargoPortValidateService.IsValidPortForCategory(currentCargoCategory.CategoryCode, localMSD1.ReportingPort, localMSD1.AssociatedPort, localMSD1.IsInbound);

            if (!isValidCategory)
            {
                if (selectedCategory12)
                {
                    ModelState.AddModelError("CargoItem.Category", $"Crude Oil cannot be carried through " + localMSD1.ReportingPort);
                }
                if (selectedCategory13)
                {
                    var portName = (localMSD1.IsInbound == true ? localMSD1.AssociatedPort : localMSD1.ReportingPort);
                    ModelState.AddModelError("CargoItem.Category", $"Oil Products cannot be carried through " + portName);
                }
            }

            bool isValidCategoryVessel = _cargoPortValidateService.IsValidVesselCargo(currentCargoCategory.CategoryCode, localMSD1.Imo);

            if (!isValidCategoryVessel)
            {
                ModelState.AddModelError("CargoItem.Category", $"Category '" + currentCargoCategory.Description + "' is not valid for the vessel '" + localMSD1.Imo + "-" + localMSD1.ShipName + "'");
            }
        }
Exemple #2
0
        public async Task <IActionResult> OnGet()
        {
            MSD1       = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
            CargoGroup = await CreateCargoGroupListAsync();

            return(Page());
        }
Exemple #3
0
        private void CargoCategoryHardValidations(MSD1 localMSD1, CargoCategory currentCargoCategory)
        {
            bool isvalid = _cargoPortValidateService.IsValidCategoryForPort(CargoItem.Category, localMSD1.AssociatedPort);

            if (!isvalid)
            {
                ModelState.AddModelError("CargoItem.Category", $" Cargo Category cannot be carried through " + "'" + localMSD1.AssociatedPort + "'");
            }

            var(allowedTonnage, avgWeightPerUnit, isTonnageExceeded, IsUnitsWithCargoZero) = _cargoPortValidateService.HasTonnagePerUnitExceeded(currentCargoCategory.CategoryCode, CargoItem.TotalUnits, CargoItem.UnitsWithCargo, CargoItem.UnitsWithoutCargo, CargoItem.GrossWeight);
            if (isTonnageExceeded)
            {
                ModelState.AddModelError("CargoItem.GrossWeight", $" Average gross weight entered '" + avgWeightPerUnit + " tonnes' per unit has exceeded maximum permitted '" + allowedTonnage + " tonnes' for Cargo Category: " + "'" + CargoItem.Category + "'");
            }
            if (!IsUnitsWithCargoZero)
            {
                ModelState.AddModelError("CargoItem.", $" The number of units without cargo must be '0' for selected " + CargoItem.Category);
            }

            bool RequiredCargoDescription = _cargoPortValidateService.IsMandatoryCargoDescription(currentCargoCategory.CategoryCode);

            if (RequiredCargoDescription && CargoItem.Description == null)
            {
                ModelState.AddModelError("CargoItem.Description", $"The Cargo description is required");
            }
        }
        private void InitialisePage()
        {
            Vessels = _context.WorldFleet.AsNoTracking().Select
                      (
                x =>
                x.Imo.ToString() +
                " - " + x.ShipName.ToString() +
                " (" + x.FlagCode.ToString() + ")"
                      )
                      .ToList();

            if (CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD1Key] != null)
            {
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));

                if (MSD1.Imo != 0)
                {
                    Vessel = MSD1.Imo.ToString() +
                             " - " + MSD1.ShipName.ToString() +
                             " (" + MSD1.FlagCode + ")";
                }
            }

            FromSummary = Helpers.ReturnBoolFromQueryString(HttpContext, "FromSummary");
        }
        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);
        }
Exemple #6
0
        public async Task OnGet_GoodTempData_GoodContext_ReturnsPageResult()
        {
            var CargoGroups = new List <CargoGroup>()
            {
                new CargoGroup {
                    Description = "TEST_DESCRIPTION"
                }
            };

            await actualContext.CargoGroup.AddRangeAsync(CargoGroups);

            actualContext.SaveChanges();
            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            var model = new CargoDetailsModel(actualContext, cargoPortValidateService)
            {
                PageContext = pageContext,
                TempData    = tempData,
                Url         = new UrlHelper(actionContext)
            };

            var result = await model.OnGetAsync();

            Assert.IsInstanceOfType(result, typeof(PageResult));
        }
        public void Setup()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PortFreightContext>()
                                 .UseInMemoryDatabase("InMemoryDb")
                                 .Options;

            var httpContext = new DefaultHttpContext();

            tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            var modelState = new ModelStateDictionary();

            actionContext = new ActionContext(httpContext, new RouteData(), new PageActionDescriptor(), modelState);

            var modelMetadataProvider = new EmptyModelMetadataProvider();

            viewData = new ViewDataDictionary(modelMetadataProvider, modelState);

            pageContext = new PageContext(actionContext)
            {
                ViewData = viewData
            };

            actualContext = new PortFreightContext(optionsBuilder);

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            CommonFunction = new HelperService(actualContext);
        }
        public async Task OnGet_GoodTempData_GoodContext_ReturnsPageResult()
        {
            List <GlobalPort> ReportingPorts = new List <GlobalPort>()
            {
                new GlobalPort {
                    Locode = "LOCODE_TEST", PortName = "PORTNAME_TEST", CountryCode = "GB"
                }
            };

            await actualContext.GlobalPort.AddRangeAsync(ReportingPorts);

            actualContext.SaveChanges();

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            var model = new VoyageDetailsModel(actualContext, CommonFunction)
            {
                PageContext = pageContext,
                TempData    = tempData,
                Url         = new UrlHelper(actionContext)
            };

            var result = model.OnGet();

            Assert.IsInstanceOfType(result, typeof(PageResult));
        }
Exemple #9
0
        public async Task <IActionResult> OnPostAddCargo()
        {
            MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));

            if (CargoItem.Group == null || CargoItem.Category == null)
            {
                byte groupCode = 0;
                if (string.IsNullOrEmpty(CargoItem.Group))
                {
                    ModelState.AddModelError("CargoItem.Group", "Select a Cargo Group");
                }
                else
                {
                    ModelState.AddModelError("CargoItem.Category", "Select a Cargo Category");
                    IsEditMode = true;
                    groupCode  = TempData.GetKeep <CargoGroup>(CargoGroupKey).GroupCode;
                }
                CargoGroup = await CreateCargoGroupListAsync();

                SetupCargoCategories(groupCode);
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
                AddViewBag();

                return(Page());
            }

            var currentCargoGroup    = TempData.GetKeep <CargoGroup>(CargoGroupKey);
            var currentCargoCategory = TempData.GetKeep <List <CargoCategory> >(CargoCategoryKey)
                                       .FirstOrDefault(x => x.Description == CargoItem.Category);

            var localMSD1 = new MSD1(TempData.Get <MSD1>(MSD1Key));

            CargoItemValidation(localMSD1, currentCargoCategory, currentCargoGroup);

            if (!ModelState.IsValid)
            {
                IsEditMode = true;
                CargoGroup = await CreateCargoGroupListAsync();

                SetupCargoCategories(currentCargoGroup.GroupCode);
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
                TextInputDisplayDriver = buildTextInputDisplayDriver(currentCargoCategory, currentCargoGroup.IsUnitised);
                AddViewBag();
                return(Page());
            }

            if (!CargoItem.TotalUnits.HasValue || CargoItem.TotalUnits == 0)
            {
                CargoItem.TotalUnits = (CargoItem.UnitsWithCargo ?? 0) + (CargoItem.UnitsWithoutCargo ?? 0);
            }


            CargoItem.Id = Guid.NewGuid();
            localMSD1.CargoSummary.Add(CargoItem);
            TempData.Put(MSD1Key, localMSD1);

            string fromSummary = TempData.Get <string>("FromSummary") ?? "false";

            return(RedirectToPage("CargoDetails", new { FromSummary = fromSummary }));
        }
Exemple #10
0
 private void MapVMtoServiceModel(MSD1 localMSD1)
 {
     var serviceLocalMSD1 = new Services.Models.MSD1_1
     {
         Imo              = localMSD1.Imo,
         ShipName         = localMSD1.ShipName,
         DeadWeight       = localMSD1.Deadweight,
         Year             = localMSD1.Year,
         Quarter          = localMSD1.Quarter,
         AssociatedPort   = localMSD1.AssociatedPort,
         ReportingPort    = localMSD1.ReportingPort,
         NumVoyages       = localMSD1.NumVoyages,
         IsInbound        = localMSD1.IsInbound,
         Msd1Id           = localMSD1.Msd1Id,
         AgentSenderID    = localMSD1.AgentSenderID,
         AgentCompanyName = localMSD1.AgentCompanyName,
         LineSenderID     = localMSD1.LineSenderID,
         LineCompanyName  = localMSD1.LineCompanyName,
         FlagCode         = localMSD1.FlagCode,
         RecordRef        = localMSD1.RecordRef
     };
     var serviceCargoItem = new Services.Models.CargoItem
     {
         Id                = CargoItem.Id,
         Category          = CargoItem.Category,
         Group             = CargoItem.Group,
         UnitsWithCargo    = CargoItem.UnitsWithCargo,
         UnitsWithoutCargo = CargoItem.UnitsWithoutCargo,
         TotalUnits        = CargoItem.TotalUnits,
         GrossWeight       = CargoItem.GrossWeight,
         Description       = CargoItem.Description
     };
 }
        public IActionResult OnGet()
        {
            MSD1   = new MSD1(TempData.Get <MSD1>(MSD1Key));
            Msd1Id = MSD1.Msd1Id;
            TempData.Put(MSD1Success, MSD1);

            return(Page());
        }
Exemple #12
0
        public async Task <IActionResult> OnGetAsync()
        {
            CargoGroup = await CreateCargoGroupListAsync();

            SetupCargoCategories(0);
            MSD1        = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
            FromSummary = Helpers.ReturnBoolFromQueryString(HttpContext, "FromSummary");
            TempData.Put("FromSummary", FromSummary.ToString());
            AddViewBag();
            return(Page());
        }
        private void InitialisePage()
        {
            Years = new List <SelectListItem>()
            {
                new SelectListItem
                {
                    Text = DateTime.Now.Year.ToString(), Value = DateTime.Now.Year.ToString()
                },
                new SelectListItem
                {
                    Text = DateTime.Now.AddYears(-1).Year.ToString(), Value = DateTime.Now.AddYears(-1).Year.ToString()
                }
            };

            Quarters = new List <SelectListItem>()
            {
                new SelectListItem
                {
                    Text = "Select a Quarter", Value = "0", Disabled = true
                },
                new SelectListItem
                {
                    Text = "Quarter 1", Value = "1"
                },
                new SelectListItem
                {
                    Text = "Quarter 2", Value = "2"
                },
                new SelectListItem
                {
                    Text = "Quarter 3", Value = "3"
                },
                new SelectListItem
                {
                    Text = "Quarter 4", Value = "4"
                },
            };

            ReportingPorts = _helperService.GetReportingPorts();
            ReportingPort  = Input.ReportingPort;


            AssociatedPorts = _helperService.GetPortsOfLoadUnload();
            if (TempData[MSD1Key] == null && TempData[MSD1Success] != null)
            {
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Success));
                TempData.Put(MSD1Key, MSD1);
                TempData.Remove(MSD1Success);
            }

            MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));

            FromSummary = Helpers.ReturnBoolFromQueryString(HttpContext, "FromSummary");
        }
Exemple #14
0
        public IActionResult OnPostRemoveCargo(Guid?Id)
        {
            if (Id != null && Id != Guid.Empty)
            {
                var localMSD1 = new MSD1(TempData.Get <MSD1>(MSD1Key));
                var cargoItem = localMSD1.CargoSummary.Where(x => x.Id == Id).SingleOrDefault();
                localMSD1.CargoSummary.Remove(cargoItem);
                TempData.Put(MSD1Key, localMSD1);
            }
            string fromSummary = TempData.Get <string>("FromSummary") ?? "false";

            return(RedirectToPage("CargoDetails", new { FromSummary = fromSummary }));
        }
Exemple #15
0
        public async Task <IActionResult> OnGetAsync()
        {
            InitialisePage();

            loggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            if (loggedInUser == null || loggedInUser.SenderId == null)
            {
                return(RedirectToPage("/Account/Logout", new { area = "Identity" }));
            }

            var senderTypesDetails = _helperService.GetSenderType(loggedInUser.SenderId);
            var AgentId            = !CustomExtensions.NotNullOrEmpty(Input.AgentSenderId) && senderTypesDetails.IsAgent == true
                ? loggedInUser.SenderId : Input.AgentSenderId;
            var LineId = !CustomExtensions.NotNullOrEmpty(Input.LineSenderId) && senderTypesDetails.IsLine == true
                ? loggedInUser.SenderId : Input.LineSenderId;

            if (LineId != null)
            {
                Input.LineSenderId = _context.ContactDetails.Where(s => s.SenderId == LineId).Select
                                     (
                    s =>
                    s.SenderId.ToString() +
                    " - " + s.CompanyName.ToString()).SingleOrDefault();
            }
            if (AgentId != null)
            {
                Input.AgentSenderId = _context.ContactDetails.Where(s => s.SenderId == AgentId).Select
                                      (
                    s =>
                    s.SenderId.ToString() +
                    " - " + s.CompanyName.ToString()).SingleOrDefault();
            }

            if (CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD1Key] != null)
            {
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
                if (CustomExtensions.NotNullOrEmpty(MSD1.AgentSenderID) || CustomExtensions.NotNullOrEmpty(MSD1.LineSenderID))
                {
                    Input.AgentSenderId = MSD1.AgentSenderID +
                                          " - " + MSD1.AgentCompanyName;

                    Input.LineSenderId = MSD1.LineSenderID +
                                         " - " + MSD1.LineCompanyName;
                }
            }

            FromSummary = Helpers.ReturnBoolFromQueryString(HttpContext, "FromSummary");

            return(Page());
        }
        public IActionResult OnPostVoyageDetails()
        {
            MSD1        = new MSD1(TempData.GetKeep <MSD1>(MSD1Success));
            MSD1.Msd1Id = null;
            MSD1.CargoSummary.Clear();
            MSD1.IsInbound      = null;
            MSD1.ReportingPort  = string.Empty;
            MSD1.AssociatedPort = string.Empty;
            MSD1.NumVoyages     = 1;
            MSD1.RecordRef      = null;
            TempData.Put(MSD1Success, MSD1);

            return(RedirectToPage("./VoyageDetails"));
        }
        private void AssignMSD1ToInput()
        {
            if (CustomExtensions.NotNullOrEmpty(TempData))
            {
                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));

                Input.Year           = MSD1.Year.ToString();
                Input.Quarter        = MSD1.Quarter.ToString();
                Input.ReportingPort  = MSD1.ReportingPort;
                Input.IsInbound      = MSD1.IsInbound;
                Input.AssociatedPort = MSD1.AssociatedPort;
                Input.NumVoyages     = MSD1.NumVoyages.ToString();
                Input.RecordRef      = MSD1.RecordRef;
            }
        }
Exemple #18
0
        public void SingleWriteBadReadReturnsNull()
        {
            var  MSD1      = new MSD1();
            uint vesselImo = 1234;

            MSD1.Imo = vesselImo;

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            tempData.Put("testKey", MSD1);

            var MSD1_out = tempData.Get <MSD1>("testkey_junk");

            Assert.IsNull(MSD1_out);
        }
Exemple #19
0
        public void SingleWriteReadReturnsCorrectValue()
        {
            var  MSD1      = new MSD1();
            uint vesselImo = 1234;

            MSD1.Imo = vesselImo;

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            tempData.Put("testKey", MSD1);

            var MSD1_out = tempData.Get <MSD1>("testkey");

            Assert.AreEqual(vesselImo, MSD1_out.Imo);
        }
        public async Task OnGet_GoodTempData_GoodContext_ReturnsResult()
        {
            var portFreightUser = new PortFreightUser
            {
                Id       = "1",
                Email    = "*****@*****.**",
                SenderId = "DFT007"
            };

            actualUserContext.Users.Add(portFreightUser);
            await actualUserContext.SaveChangesAsync();

            var senderType = new List <SenderType>()
            {
                new SenderType {
                    SenderId = "DFT007", IsAgent = true, IsLine = false, IsPort = true
                }
            };

            actualContext.SenderType.AddRange(senderType);
            await actualContext.SaveChangesAsync();

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            pageModel = new CompanyDetailsModel(actualContext, CommonFunction, mockUserManager.Object)
            {
                PageContext = pageContext,
                TempData    = tempData,
                Url         = new UrlHelper(actionContext)
            };

            mockUserManager.Setup(p => p.GetUserAsync(httpContext.User)).ReturnsAsync(portFreightUsers.FirstOrDefault(x => x.Id == "1"));

            var result = await pageModel.OnGetAsync();

            Assert.IsNotNull(result);
            Assert.IsNotNull(pageModel.AgentSenders);
            Assert.IsNotNull(pageModel.LineSenders);
            Assert.IsNotNull(pageModel.Input.AgentSenderId);
            Assert.IsNull(pageModel.Input.LineSenderId == "" ? null : pageModel.Input.LineSenderId);
            Assert.IsNotNull(pageModel.User);
            Assert.AreEqual(pageModel.loggedInUser.Email, portFreightUser.Email);
        }
        private void AssignInputToMSD1()
        {
            MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));

            if (!FromSummary && (MSD1.AssociatedPort != Input.AssociatedPort || MSD1.ReportingPort != Input.ReportingPort))
            {
                MSD1.CargoSummary.Clear();
            }

            MSD1.Year           = uint.Parse(Input.Year);
            MSD1.Quarter        = ushort.Parse(Input.Quarter);
            MSD1.ReportingPort  = Input.ReportingPort;
            MSD1.IsInbound      = Input.IsInbound;
            MSD1.AssociatedPort = Input.AssociatedPort;
            MSD1.NumVoyages     = uint.Parse(Input.NumVoyages);
            MSD1.RecordRef      = Input.RecordRef;
            MSD1.VoyageDate     = ConcatenateDate();
        }
        public IActionResult OnPost(string vesselDetails)
        {
            Vessel = vesselDetails;

            if (Vessel != null)
            {
                ModelState.Clear();
                TryValidateModel(Vessel);
            }

            if (!ModelState.IsValid)
            {
                InitialisePage();

                return(Page());
            }

            try
            {
                uint imo    = Convert.ToUInt32(Vessel.Split('-').FirstOrDefault().TrimEnd());
                var  vessel = _context.WorldFleet
                              .Where(a => a.Imo == imo)
                              .First();

                MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key))
                {
                    Imo        = vessel.Imo,
                    Deadweight = vessel.Deadweight,
                    ShipName   = vessel.ShipName,
                    FlagCode   = vessel.FlagCode
                };
                TempData.Put(MSD1Key, MSD1);

                return(RedirectToPage("./VoyageDetails", new { FromSummary = FromSummary.ToString(), IsEdited = FromSummary.ToString() }));
            }

            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                ModelState.AddModelError("CustomError", "Enter a valid IMO number or Vessel Name");
                InitialisePage();
                return(Page());
            }
        }
        public async Task OnPost_ModelStateInvalid_ReturnsPageResult()
        {
            var portFreightUser = new PortFreightUser
            {
                Id       = "1",
                Email    = "*****@*****.**",
                SenderId = "DFT007"
            };

            actualUserContext.Users.Add(portFreightUser);
            await actualUserContext.SaveChangesAsync();

            var senderType = new List <SenderType>()
            {
                new SenderType {
                    SenderId = "DFT007", IsAgent = true, IsLine = false, IsPort = true
                }
            };

            actualContext.SenderType.AddRange(senderType);
            actualContext.SaveChanges();

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            pageModel = new CompanyDetailsModel(actualContext, CommonFunction, mockUserManager.Object)
            {
                PageContext = pageContext,
                TempData    = tempData,
                Url         = new UrlHelper(actionContext)
            };

            mockUserManager.Setup(p => p.GetUserAsync(httpContext.User)).ReturnsAsync(portFreightUsers.FirstOrDefault(x => x.Id == "1"));

            pageModel.ModelState.AddModelError("LineSenderId", "Line's Sender Id is required.");
            var result = pageModel.OnPost();

            Assert.IsNotNull(result);
            Assert.IsNull(pageModel.Input.LineSenderId == "" ? null : pageModel.Input.LineSenderId);
            Assert.IsInstanceOfType(result, typeof(PageResult));
        }
        public void Setup()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PortFreightContext>()
                                 .UseInMemoryDatabase("InMemoryDb")
                                 .Options;
            var optionsBuilderUser = new DbContextOptionsBuilder <UserDbContext>()
                                     .UseInMemoryDatabase("InMemoryUserDb")
                                     .Options;

            actualContext = new PortFreightContext(optionsBuilder);

            var httpContext = new DefaultHttpContext();

            tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            var modelState = new ModelStateDictionary();

            actionContext = new ActionContext(httpContext, new RouteData(), new PageActionDescriptor(), modelState);
            var modelMetadataProvider = new EmptyModelMetadataProvider();

            viewData = new ViewDataDictionary(modelMetadataProvider, modelState);

            pageContext = new PageContext(actionContext)
            {
                ViewData = viewData
            };

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);
            logger             = new Mock <ILogger <VesselDetailsModel> >();
            helperService      = new HelperService(actualContext);
            vesselDetailsModel = new VesselDetailsModel(actualContext, logger.Object, helperService)
            {
                PageContext = pageContext,
                TempData    = tempData,
                Url         = new UrlHelper(actionContext)
            };
        }
        public void Setup()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PortFreightContext>()
                                 .UseInMemoryDatabase("InMemoryDb")
                                 .Options;
            var optionsBuilderUser = new DbContextOptionsBuilder <UserDbContext>()
                                     .UseInMemoryDatabase("InMemoryUserDb")
                                     .Options;

            httpContext = new DefaultHttpContext();
            var modelState = new ModelStateDictionary();

            actionContext         = new ActionContext(httpContext, new RouteData(), new PageActionDescriptor(), modelState);
            modelMetadataProvider = new EmptyModelMetadataProvider();
            viewData = new ViewDataDictionary(modelMetadataProvider, modelState);
            tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            pageContext = new PageContext(actionContext)
            {
                ViewData = viewData
            };

            actualContext     = new PortFreightContext(optionsBuilder);
            actualUserContext = new UserDbContext(optionsBuilderUser);

            CommonFunction = new HelperService(actualContext);

            portFreightUsers = new List <PortFreightUser>
            {
                new PortFreightUser()
                {
                    Id = "1", Email = "*****@*****.**", SenderId = "DFT007", UserName = "******"
                }
            };

            mockUserManager = MockUserManager(portFreightUsers);
            mockUserManager.Setup(p => p.GetUserAsync(httpContext.User)).ReturnsAsync(portFreightUsers.FirstOrDefault());

            MSD1 Msd1 = new MSD1();

            tempData["MSD1Key"] = JsonConvert.SerializeObject(Msd1);

            var orgList = new List <OrgList>()
            {
                new OrgList {
                    OrgId = "ABC123", OrgName = "The ABC Company", IsAgent = true, IsLine = false, IsPort = false
                },
                new OrgList {
                    OrgId = "ABC007", OrgName = "Another ABC Company", IsAgent = false, IsLine = true, IsPort = false
                },
                new OrgList {
                    OrgId = "XYZ123", OrgName = "X Y Z ltd", IsAgent = false, IsLine = false, IsPort = true
                }
            };

            actualContext.OrgList.AddRange(orgList);

            var contactDetails = new List <ContactDetails>()
            {
                new ContactDetails {
                    CompanyName = "Sun and Send Cargo Ltd", SenderId = "DFT007"
                },
                new ContactDetails {
                    CompanyName = "blahblah", SenderId = "DFT001"
                },
                new ContactDetails {
                    CompanyName = "Monshur Industries", SenderId = "DFT003"
                }
            };

            actualContext.ContactDetails.AddRange(contactDetails);
            actualContext.SaveChanges();
        }
Exemple #26
0
        private void ManualModelValidation(MSD1 localMSD1)
        {
            var currentCargoGroup    = TempData.GetKeep <CargoGroup>(CargoGroupKey);
            var currentCargoCategory = TempData.GetKeep <List <CargoCategory> >(CargoCategoryKey).FirstOrDefault(x => x.Description == CargoItem.Category);

            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", "Enter number of units");
            }

            if (numUnitsWithCargoVisible && (!CargoItem.UnitsWithCargo.HasValue))
            {
                ModelState.AddModelError("CargoItem.UnitsWithCargo", "Enter number of units carrying cargo");
            }

            if (numUnitsWithoutCargoVisible && (!CargoItem.UnitsWithoutCargo.HasValue))
            {
                ModelState.AddModelError("CargoItem.UnitsWithoutCargo", "Enter number of units without cargo");
            }

            if (grossWeightVisible)
            {
                if (!CargoItem.GrossWeight.HasValue)
                {
                    ModelState.AddModelError("CargoItem.GrossWeight", "Enter the weight. Type 0 if no weight available");
                }
                else
                {
                    if (!numUnitsVisible && !numUnitsWithCargoVisible && !numUnitsWithoutCargoVisible && CargoItem.GrossWeight == 0)
                    {
                        ModelState.AddModelError("CargoItem.GrossWeight", "Enter weight greater than 0");
                    }
                    else if (numUnitsVisible && !numUnitsWithCargoVisible && !numUnitsWithoutCargoVisible && CargoItem.GrossWeight == 0)
                    {
                        ModelState.AddModelError("CargoItem.GrossWeight", "Enter weight greater than 0");
                    }
                    else
                    {
                        var totalGrossWeight = localMSD1.CargoSummary.Sum(x => x.GrossWeight) + CargoItem.GrossWeight;
                        if ((CargoItem.GrossWeight - DeadweightErrorMargin > localMSD1.Deadweight * localMSD1.NumVoyages) ||
                            (totalGrossWeight - DeadweightErrorMargin > localMSD1.Deadweight * localMSD1.NumVoyages))
                        {
                            ModelState.AddModelError("CargoItem.GrossWeight",
                                                     totalGrossWeight + " exceeds the deadweight of this ship. If deadweight of the ship is incorrect, contact the helpdesk");
                        }
                    }
                }
            }

            if (numUnitsWithCargoVisible &&
                numUnitsWithoutCargoVisible &&
                CargoItem.UnitsWithCargo == 0 &&
                CargoItem.UnitsWithoutCargo == 0)
            {
                ModelState.AddModelError("CargoItem.UnitsWithCargo", "Number of units with and without cargo cannot both be 0");
                ModelState.AddModelError("CargoItem.UnitsWithoutCargo", "Number of units with and without cargo cannot both be 0");
            }

            if (numUnitsWithCargoVisible && CargoItem.UnitsWithCargo > 0 && CargoItem.GrossWeight == 0)
            {
                ModelState.AddModelError("CargoItem.GrossWeight",
                                         "You entered " + CargoItem.UnitsWithCargo + " units with cargo. Enter the weight of this cargo");
            }

            if (numUnitsWithCargoVisible && CargoItem.UnitsWithCargo == 0 && CargoItem.GrossWeight > 0)
            {
                ModelState.AddModelError("CargoItem.UnitsWithCargo",
                                         "You entered weight as " + CargoItem.GrossWeight + " tonnes. Enter number of units that were carrying this cargo");
            }
        }
Exemple #27
0
        public async Task <IActionResult> OnPostContinue()
        {
            MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
            int totalSummaryItems = MSD1.CargoSummary.Count;

            FromSummary = Boolean.TryParse(TempData.Get <string>("FromSummary"), out bool result) ? result : false;

            if (CargoItem.Group == null || CargoItem.Category == null)
            {
                byte groupCode = 0;
                if (CargoItem.Group == null)
                {
                    if (totalSummaryItems > 0)
                    {
                        if (FromSummary)
                        {
                            return(RedirectToPage("./SubmitReturn", new { FromSummary = "true", IsEdited = "true" }));
                        }
                        return(RedirectToPage("./SubmitReturn"));
                    }

                    ModelState.AddModelError("CargoItem.Group", "Select a Cargo Group");
                }
                else
                {
                    ModelState.AddModelError("CargoItem.Category", "Select a Cargo Category");
                    IsEditMode = true;
                    groupCode  = TempData.GetKeep <CargoGroup>(CargoGroupKey).GroupCode;
                }
                CargoGroup = await CreateCargoGroupListAsync();

                SetupCargoCategories(groupCode);
                AddViewBag();
                return(Page());
            }
            var currentCargoGroup    = TempData.GetKeep <CargoGroup>(CargoGroupKey);
            var currentCargoCategory = TempData.GetKeep <List <CargoCategory> >(CargoCategoryKey).FirstOrDefault(x => x.Description == CargoItem.Category);
            var localMSD1            = new MSD1(TempData.Get <MSD1>(MSD1Key));

            CargoItemValidation(localMSD1, currentCargoCategory, currentCargoGroup);

            if (!ModelState.IsValid)
            {
                IsEditMode = true;
                CargoGroup = await CreateCargoGroupListAsync();

                SetupCargoCategories(currentCargoGroup.GroupCode);
                TextInputDisplayDriver = buildTextInputDisplayDriver(currentCargoCategory, currentCargoGroup.IsUnitised);
                AddViewBag();
                return(Page());
            }

            if (!CargoItem.TotalUnits.HasValue || CargoItem.TotalUnits == 0)
            {
                CargoItem.TotalUnits = (CargoItem.UnitsWithCargo ?? 0) + (CargoItem.UnitsWithoutCargo ?? 0);
            }

            CargoItem.Id = Guid.NewGuid();
            localMSD1.CargoSummary.Add(CargoItem);
            TempData.Put(MSD1Key, localMSD1);

            TempData.Remove(CargoGroupKey);
            TempData.Remove(CargoCategoryKey);

            if (FromSummary)
            {
                return(RedirectToPage("./SubmitReturn", new { FromSummary = "true", IsEdited = "true" }));
            }
            return(RedirectToPage("./SubmitReturn"));
        }
 private void GetMSD1()
 {
     MSD1 = new MSD1(TempData.GetKeep <MSD1>(MSD1Key));
 }