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");
        }
        public async Task <IActionResult> OnGetAsync(string sortOrder)
        {
            LoggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            InitialisePage(LoggedInUser);
            MSD3VM = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();

            string submitted = CustomExtensions.NotNullOrEmpty(TempData) && TempData[SubmittedKey] != null?TempData.GetKeep <string>(SubmittedKey) : "";

            var existingParent = FindSubmission();

            if (existingParent != null)
            {
                TempData.Put("SubmittedKey", "true");
                TempData.Remove(MSD3Key);
                AssignMSD3ToInput(existingParent);
            }
            else
            {
                string slectedYearQuarter = MSD23.Year.ToString() + MSD23.Quarter.ToString();
                if (submitted.ToString() == "true")
                {
                    MSD3VM.AgentSummary.Clear();
                    TempData.Remove(MSD3Key);
                }
                else if (submitted.ToString() != "false" + slectedYearQuarter)
                {
                    MSD3VM.AgentSummary.Clear();
                    TempData.Remove(MSD3Key);
                }
                TempData.Put("SubmittedKey", "false" + slectedYearQuarter);
            }

            return(Page());
        }
 private void InitialisePage(PortFreightUser user)
 {
     MSD23 = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD23Key] != null ? new MSD23(TempData.GetKeep <MSD23>(MSD23Key)) : new MSD23();
     var locodes = (from p in _context.SenderIdPort
                    join t in _context.SenderType on p.SenderId equals t.SenderId
                    where (t.IsPort == true) && p.SenderId == user.SenderId
                    select p.Locode).ToList();
 }
 private void InitialisePage(PortFreightUser user)
 {
     MSD23   = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD23Key] != null ? new MSD23(TempData.GetKeep <MSD23>(MSD23Key)) : new MSD23();
     Senders = _context.OrgList
               .Where(s => s.IsAgent || s.IsLine)
               .Select(s =>
                       s.OrgId.ToString() + " - " + s.OrgName.ToString()
                       ).ToList();
 }
        public async Task <IActionResult> OnPostCargoReturn(string id)
        {
            string portname = await _context.GlobalPort.AsNoTracking().Where(x => x.Locode == Input.ReportingPort).Select(x => x.PortName).FirstOrDefaultAsync();

            MSD23          = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD23Key] != null ? new MSD23(TempData.GetKeep <MSD23>(MSD23Key)) : new MSD23();
            MSD23.Port     = Input.ReportingPort;
            MSD23.Year     = ushort.Parse(id.Substring(1, 4));
            MSD23.Quarter  = ushort.Parse(id.Substring(0, 1));
            MSD23.PortName = portname;
            TempData.Put(MSD23Key, MSD23);

            return(RedirectToPage("./CargoReturn"));
        }
コード例 #6
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());
        }
        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;
            }
        }
        public async Task OnPostRemoveAgent(Guid?Id)
        {
            ModelState.Clear();
            LoggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            if (Id != null && Id != Guid.Empty)
            {
                var localMSD3 = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();;
                var agentItem = localMSD3.AgentSummary.Where(x => x.Id == Id).SingleOrDefault();
                localMSD3.AgentSummary.Remove(agentItem);
                TempData.Put(MSD3Key, localMSD3);
            }
            InitialisePage(LoggedInUser);
            MSD3VM = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();
        }
コード例 #9
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                InitialisePage();
                return(Page());
            }

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

            MSD1.AgentSenderID = Input.AgentSenderId.Split('-').FirstOrDefault().TrimEnd();
            MSD1.LineSenderID  = Input.LineSenderId.Split('-').FirstOrDefault().TrimEnd();

            MSD1.AgentCompanyName = Input.AgentSenderId.Split('-').LastOrDefault().TrimStart();
            MSD1.LineCompanyName  = Input.LineSenderId.Split('-').LastOrDefault().TrimStart();
            TempData.Put(MSD1Key, MSD1);

            return(RedirectToPage("./VesselDetails", new { FromSummary = FromSummary.ToString(), IsEdited = FromSummary.ToString() }));
        }
        public async Task OnPostAddAgent()
        {
            ModelState.Clear();
            LoggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            if (Input.SenderId == null)
            {
                ModelState.AddModelError("Input.SenderId", "Enter a valid shipping agent");
            }
            var localMSD3 = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();

            if (localMSD3.AgentSummary.Count > 0)
            {
                bool isAlreadyAdded = localMSD3.AgentSummary.Any(x => x.ShippingAgent == Input.SenderId);
                if (isAlreadyAdded)
                {
                    ModelState.AddModelError("Input.SenderId", "Agent or line is already added");
                }
            }

            if (!ModelState.IsValid)
            {
                InitialisePage(LoggedInUser);
            }
            else
            {
                AgentItem = new Agent
                {
                    Id            = Guid.NewGuid(),
                    ShippingAgent = Input.SenderId
                };
                localMSD3.AgentSummary.Add(AgentItem);
                TempData.Put(MSD3Key, localMSD3);
                Input.SenderId = "";
                InitialisePage(LoggedInUser);
            }
            MSD3VM = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();
        }
        private void AssignMSD3ToInput(Msd3 msd3)
        {
            var localMSD3 = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();;

            MSD3VM.AgentSummary.Clear();
            MSD23          = new MSD23(TempData.GetKeep <MSD23>(MSD23Key));
            MSD23.Year     = msd3.Year;
            MSD23.Quarter  = msd3.Quarter;
            MSD23.Port     = msd3.ReportingPort;
            MSD23.PortName = _helperService.GetPortNameByCode(msd3.ReportingPort);
            foreach (Msd3agents msd3Agent in msd3.Msd3agents)
            {
                Agent agent = new Agent
                {
                    Id            = Guid.NewGuid(),
                    ShippingAgent = _context.OrgList.Where(s => s.OrgId == msd3Agent.SenderId)
                                    .Select(s => s.OrgId.ToString() + " - " + s.OrgName.ToString()).FirstOrDefault()
                };
                MSD3VM.AgentSummary.Add(agent);
                localMSD3.AgentSummary.Add(agent);
            }
            ;
            TempData.Put(MSD3Key, localMSD3);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            LoggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            MSD3VM = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD3Key] != null ? new MSD3ViewModel(TempData.GetKeep <MSD3ViewModel>(MSD3Key)) : new MSD3ViewModel();
            MSD23  = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD23Key] != null ? new MSD23(TempData.GetKeep <MSD23>(MSD23Key)) : new MSD23();
            if (MSD3VM.AgentSummary.Count < 1)
            {
                ModelState.AddModelError("Input.SenderId", "No shipping Line or Agents entered");
            }

            msd3UniqueKey = _helperService.GetUniqueKey();
            if (msd3UniqueKey == null)
            {
                ModelState.AddModelError("UniqueKeyError", "Failed to generate a unique Key");
            }

            if (!ModelState.IsValid)
            {
                InitialisePage(LoggedInUser);
                return(Page());
            }

            MSD3Data = new Msd3
            {
                Id            = msd3UniqueKey,
                SenderId      = LoggedInUser.SenderId,
                ReportingPort = MSD23.Port,
                Year          = MSD23.Year,
                Quarter       = MSD23.Quarter,
                DataSourceId  = (uint)DataSource.WEB,
                CreatedDate   = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc),
                ModifiedDate  = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc),
                CreatedBy     = LoggedInUser.Email.ToString(),
                LastUpdatedBy = LoggedInUser.Email.ToString()
            };

            var existingParent = FindSubmission();

            if (existingParent != null)
            {
                msd3UniqueKey        = existingParent.Id;
                MSD3Data.Id          = existingParent.Id;
                MSD3Data.CreatedDate = existingParent.CreatedDate;
                MSD3Data.CreatedBy   = existingParent.CreatedBy;
                _context.Entry(existingParent).CurrentValues.SetValues(MSD3Data);

                _context.Msd3agents.RemoveRange(existingParent.Msd3agents);

                foreach (Agent item in MSD3VM.AgentSummary)
                {
                    Msd3agents agentSummary = new Msd3agents
                    {
                        Msd3Id   = msd3UniqueKey,
                        SenderId = item.ShippingAgent.Split('-').FirstOrDefault().TrimEnd()
                    };
                    existingParent.Msd3agents.Add(agentSummary);
                }
                ;
            }
            else
            {
                foreach (Agent item in MSD3VM.AgentSummary)
                {
                    Msd3agents agentSummary = new Msd3agents
                    {
                        Msd3Id   = msd3UniqueKey,
                        SenderId = item.ShippingAgent.Split('-').FirstOrDefault().TrimEnd()
                    };
                    MSD3Data.Msd3agents.Add(agentSummary);
                }
                ;
                await _context.AddAsync(MSD3Data);
            }

            await _context.SaveChangesAsync();

            TempData.Remove(MSD3Key);

            return(RedirectToPage("./Success"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            LoggedInUser = await _userManager.GetUserAsync(HttpContext.User);

            MSD23 = CustomExtensions.NotNullOrEmpty(TempData) && TempData[MSD23Key] != null ? new MSD23(TempData.GetKeep <MSD23>(MSD23Key)) : new MSD23();

            if (Input.PassengerVehiclesInwards > Input.UnitsInwards)
            {
                ModelState.AddModelError("Input.PassengerVehiclesInwards", $"Passenger Vehicle Inwards cannot be greater than total number of units inwards");
            }
            if (Input.PassengerVehiclesOutwards > Input.UnitsOutwards)
            {
                ModelState.AddModelError("Input.PassengerVehiclesOutwards", $"Passenger Vehicle Outwards cannot be greater than total number of units outwards");
            }
            if (Input.GrossWeightInwards != null)
            {
                var(previousYearGWTInward, thresoldInward, boxVisibleInward) = _msd2DataService.ValidateGrossWeightInwards((decimal)Input.GrossWeightInwards, MSD23.Year, MSD23.Quarter, MSD23.Port, LoggedInUser.SenderId);
                PreviousYearGWTInward = previousYearGWTInward;
                if (boxVisibleInward)
                {
                    IsInwardBoxVisible = boxVisibleInward;
                    if (Input.GrossWeightInwardsDescription == null)
                    {
                        ModelState.AddModelError("Input_GrossWeightInwardsDescription", $"Check gross weight (inwards) and enter description if correct");
                    }
                }
                else
                {
                    ModelState.Remove("Input_InwardsUnitDescription");
                    Input.GrossWeightInwardsDescription = null;
                }
            }
            if (Input.GrossWeightOutwards != null)
            {
                var(previousYearGWTOutward, thresoldOutward, boxVisibleOutward) = _msd2DataService.ValidateGrossWeightOutwards((decimal)Input.GrossWeightOutwards, MSD23.Year, MSD23.Quarter, MSD23.Port, LoggedInUser.SenderId);
                PreviousYearGWTOutward = previousYearGWTOutward;
                if (boxVisibleOutward)
                {
                    IsOutwardBoxVisible = boxVisibleOutward;
                    if (Input.GrossWeightOutwardsDescription == null)
                    {
                        ModelState.AddModelError("Input_GrossWeightOutwardsDescription", $"Check gross weight (outwards) and enter description if correct");
                    }
                }
                else
                {
                    Input.GrossWeightOutwardsDescription = null;
                }
            }

            if (Input.UnitsInwards != null)
            {
                var(previousYearUnitsInward, thresoldInward, boxVisibleUintInward) = _msd2DataService.ValidateUnitsInwards(Input.UnitsInwards, MSD23.Year, MSD23.Quarter, MSD23.Port, LoggedInUser.SenderId);
                PreviousYearUintInward = previousYearUnitsInward;
                if (boxVisibleUintInward)
                {
                    IsInwardUnitBoxVisible = boxVisibleUintInward;
                    if (Input.InwardsUnitDescription == null)
                    {
                        ModelState.AddModelError("Input_InwardsUnitDescription", $"Check units (inwards) and enter description if correct");
                    }
                }
                else
                {
                    Input.InwardsUnitDescription = null;
                }
            }

            if (Input.UnitsOutwards != null)
            {
                var(previousYearUnitsOutward, thresoldOutward, boxVisibleUintOutward) = _msd2DataService.ValidateUnitsOutwards(Input.UnitsOutwards, MSD23.Year, MSD23.Quarter, MSD23.Port, LoggedInUser.SenderId);
                PreviousYearUintOutward = previousYearUnitsOutward;
                if (boxVisibleUintOutward)
                {
                    IsOutwardUnitBoxVisible = boxVisibleUintOutward;
                    if (Input.OutwardsUnitDescription == null)
                    {
                        ModelState.AddModelError("Input_OutwardsUnitDescription", $"Check units (outwards) and enter description if correct");
                    }
                }
                else
                {
                    Input.OutwardsUnitDescription = null;
                }
            }

            if (!ModelState.IsValid)
            {
                InitialisePage(LoggedInUser);
                return(Page());
            }
            var MSD2Data = new Msd2
            {
                SenderId                      = LoggedInUser.SenderId,
                ReportingPort                 = MSD23.Port,
                Year                          = MSD23.Year,
                Quarter                       = MSD23.Quarter,
                GrossWeightInward             = (decimal)Input.GrossWeightInwards,
                InwardGrossWeightDescription  = Input.GrossWeightInwardsDescription,
                TotalUnitsInward              = (uint)Input.UnitsInwards,
                InwardUnitDescription         = Input.InwardsUnitDescription,
                PassengerVehiclesInward       = Input.UnitsInwards == 0 ? 0 : Input.PassengerVehiclesInwards ?? 0,
                GrossWeightOutward            = (decimal)Input.GrossWeightOutwards,
                OutwardGrossWeightDescription = Input.GrossWeightOutwardsDescription,
                TotalUnitsOutward             = (uint)Input.UnitsOutwards,
                OutwardUnitDescription        = Input.OutwardsUnitDescription,
                PassengerVehiclesOutward      = Input.UnitsOutwards == 0 ? 0 : Input.PassengerVehiclesOutwards ?? 0,
                DataSourceId                  = (uint)DataSource.WEB,
                CreatedDate                   = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc),
                ModifiedDate                  = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc),
                CreatedBy                     = LoggedInUser.Email.ToString(),
                LastUpdatedBy                 = LoggedInUser.Email.ToString()
            };
            var existingParent = FindSubmission();

            if (existingParent != null)
            {
                MSD2Data.Id            = existingParent.Id;
                MSD2Data.ReportingPort = existingParent.ReportingPort;
                MSD2Data.Year          = existingParent.Year;
                MSD2Data.Quarter       = existingParent.Quarter;
                MSD2Data.DataSourceId  = existingParent.DataSourceId;
                MSD2Data.CreatedDate   = existingParent.CreatedDate;
                MSD2Data.CreatedBy     = existingParent.CreatedBy;
                _context.Entry(existingParent).CurrentValues.SetValues(MSD2Data);
            }
            else
            {
                await _context.AddAsync(MSD2Data);
            }
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Success"));
        }