public void Add(Msd1Data msd1)
 {
     if (msd1 != null)
     {
         _context.Msd1Data.Add(msd1);
         _context.SaveChanges();
         _context.Entry(msd1).State = EntityState.Detached;
     }
 }
Ejemplo n.º 2
0
 public void Add(Msd3 msd3)
 {
     if (msd3 == null)
     {
         return;
     }
     _context.Msd3.Add(msd3);
     _context.SaveChanges();
     _context.Entry(msd3).State = EntityState.Detached;
 }
Ejemplo n.º 3
0
 public void AddLogFileData(LogFileData logFileData)
 {
     _context.LogfileData.Add(logFileData);
     _context.SaveChanges();
     _context.Entry(logFileData).State = EntityState.Detached;
 }
        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"));
        }