public void Add(Msd2 msd2)
 {
     if (msd2 != null)
     {
         msd2.Id = _context.Msd2.Select(x => x.Id).Max() + 1;
         _context.Msd2.Add(msd2);
         _context.SaveChanges();
     }
 }
        public string ValidateMSD2InwardOutwadCargoWeight(Msd2 msd2Data)
        {
            var validateInwardAndOutwardGrossWeight = string.Empty;

            if (msd2Data != null)
            {
                validateInwardAndOutwardGrossWeight = (msd2Data.GrossWeightInward == 0 && msd2Data.GrossWeightOutward == 0) ?
                                                      "Inward and Outward Gross weight both can't be 0.Enter a valid gross weight or contact the helpdesk for advice." : string.Empty;
            }
            return(validateInwardAndOutwardGrossWeight);
        }
예제 #3
0
        public IActionResult OnGet()
        {
            try
            {
                msd2 = TempData.GetKeep <Msd2>("Msd2");
            }
            catch
            {
                return(Page());
            }

            return(Page());
        }
예제 #4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Msd2 = await _context.Msd2.FirstOrDefaultAsync(m => m.Id == id);

            if (Msd2 == null)
            {
                return(NotFound());
            }
            return(Page());
        }
 public MSD2FileProcess(Msd2 msd2,
                        FlatFile fileInfo,
                        ValidateMsdData validateMsdData,
                        IHelperService helperService,
                        IFileProcessService fileProcessService,
                        IMsd2DataService msd2DataService,
                        ILogger <MSD2FileProcess> logger
                        )
 {
     _msd2               = msd2;
     _fileInfo           = fileInfo;
     _validateMsdData    = validateMsdData;
     _helperService      = helperService;
     _fileProcessService = fileProcessService;
     _msd2DataService    = msd2DataService;
     _logger             = logger;
     recordErrors        = new StringBuilder();
     bodyErrorMsg        = new StringBuilder();
 }
예제 #6
0
        public IActionResult OnPost(int id)
        {
            try
            {
                Msd2 ToRemove = _context.Msd2.FirstOrDefault(x => x.Id == id);

                _context.Msd2.Remove(ToRemove);

                _context.SaveChanges();

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

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

            return(Page());
        }
 private void AssignMSD2ToInput(Msd2 msd2)
 {
     MSD23                                = new MSD23(TempData.GetKeep <MSD23>(MSD23Key));
     MSD23.Year                           = msd2.Year;
     MSD23.Quarter                        = msd2.Quarter;
     MSD23.Port                           = msd2.ReportingPort;
     MSD23.PortName                       = _helperService.GetPortNameByCode(msd2.ReportingPort);
     Input.GrossWeightInwards             = (double)msd2.GrossWeightInward;
     Input.UnitsInwards                   = msd2.TotalUnitsInward;
     Input.InwardsUnitDescription         = msd2.InwardUnitDescription;
     Input.PassengerVehiclesInwards       = msd2.PassengerVehiclesInward;
     Input.GrossWeightOutwards            = (double)msd2.GrossWeightOutward;
     Input.UnitsOutwards                  = msd2.TotalUnitsOutward;
     Input.OutwardsUnitDescription        = msd2.OutwardUnitDescription;
     Input.PassengerVehiclesOutwards      = msd2.PassengerVehiclesOutward;
     Input.GrossWeightInwardsDescription  = msd2.InwardGrossWeightDescription;
     Input.GrossWeightOutwardsDescription = msd2.OutwardGrossWeightDescription;
     IsInwardBoxVisible                   = msd2.InwardGrossWeightDescription == null ? false : true;
     IsInwardUnitBoxVisible               = msd2.InwardUnitDescription == null ? false : true;
     IsOutwardBoxVisible                  = msd2.OutwardGrossWeightDescription == null ? false : true;
     IsOutwardUnitBoxVisible              = msd2.OutwardUnitDescription == null ? false : true;
 }
        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"));
        }