public async Task <IActionResult> OnPostDeleteBucketObject(string FileToDelete)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var TempDataList = TempData.GetKeep <InputModel>("FileList");
            var ToRemove     = TempDataList.FileList.SingleOrDefault(a => a.FileName == FileToDelete);

            _options.ObjectName = MakeFileName(FileToDelete, user.SenderId);
            try
            {
                IOrderedEnumerable <Google.Apis.Storage.v1.Data.Object> bucketItems = _storage.ListObjects(_options.BucketName).OrderBy(x => x.TimeCreated);
                if (bucketItems.Any(x => x.Name == _options.ObjectName))
                {
                    await _storage.DeleteObjectAsync(_options.BucketName, _options.ObjectName);
                }
                else
                {
                    _logger.LogError("File does not exist: " + _options.BucketName, _options.ObjectName + " : " + "Please contact help desk for further advice.", string.Empty, "");
                }

                FileUploadInfo fileToRemove = _context.FileUploadInfo.Where(x => x.FileName == FileToDelete || x.FileName == _options.ObjectName).LastOrDefault();
                if (fileToRemove != null)
                {
                    TempDataList.FileList.Remove(ToRemove);
                    _context.FileUploadInfo.Remove(fileToRemove);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    string errorMessage = "An error occured while removing the selected file " + FileToDelete + " , please contact help desk for further help";
                    ModelState.AddModelError("fileToRemove.FileName", errorMessage.ToString());
                    _logger.LogError("Removing file error: " + _options.BucketName, _options.ObjectName + " : " + "An error while removing the file, either not found or null parameter passed", string.Empty, "");

                    TempDataList.FileList.ForEach(x => Input.FileList.Add(x));

                    return(Page());
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", e.ToString());
                _logger.LogError("Removing file error: " + _options.BucketName, _options.ObjectName + " : " + e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty, e.StackTrace);
                TempData.Put("FileList", TempDataList);

                return(Page());
            }

            TempData.Put("FileList", TempDataList);

            return(RedirectToPage());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                ModelState.AddModelError("CustomError", "There has been an error please try again");
            }

            try
            {
                GlobalPort = await _context.GlobalPort.FindAsync(id);

                if (GlobalPort != null)
                {
                    _context.GlobalPort.Remove(GlobalPort);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Index", new { message = "Port deleted" }));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", e.InnerException.Message);
            }
            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(GlobalPort).State = EntityState.Modified;

            try
            {
                if (GlobalPort.StatisticalPort == null && GlobalPort.CountryCode.ToUpper() == "GB")
                {
                    GlobalPort.StatisticalPort = GlobalPort.Locode;
                }

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GlobalPortExists(GlobalPort.Locode))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index", new { message = "Edit successful" }));
        }
Ejemplo n.º 4
0
        public async Task OnGet_WhenRespondentDetailsAvailableInDb_PopulateModel()
        {
            var senderType = new SenderType()
            {
                SenderId = "Test1234",
                IsAgent  = true,
                IsLine   = false,
                IsPort   = false
            };
            var senderIdPort = new SenderIdPort
            {
                SenderId = "Test1234",
                Locode   = "ABC456"
            };
            await actualContext.SenderType.AddAsync(senderType);

            await actualContext.SenderIdPort.AddAsync(senderIdPort);

            await actualContext.SaveChangesAsync();

            var result = (PageResult)await model.OnGetAsync();

            Assert.IsNotNull(result);
            Assert.IsNotNull(model.SenderType.SenderId);
            Assert.IsTrue(model.SenderType.IsAgent);
            Assert.IsFalse(model.SenderType.IsLine);
            Assert.AreEqual(portFreightUsers.FirstOrDefault().SenderId, model.SenderType.SenderId);
            Assert.IsInstanceOfType(result, typeof(PageResult));
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
        public void OnPostAsync_WhenUserIsNotinPreApprovedUserList_ShowInvitationErroMsg()
        {
            var preApprovedUser = new PreApprovedUser
            {
                EmailAddress = "*****@*****.**",
                SenderId     = "Test1234"
            };

            _usercontext.PreApprovedUsers.Add(preApprovedUser);

            var portFreightUser = new PortFreightUser
            {
                Email          = "*****@*****.**",
                SenderId       = "Test1234",
                EmailConfirmed = true
            };

            _usercontext.Users.Add(portFreightUser);
            _usercontext.SaveChangesAsync();

            var org = new OrgList
            {
                OrgId       = "TST001",
                SubmitsMsd1 = false,
                SubmitsMsd2 = true
            };

            _portfreightContext.OrgList.Add(org);
            _portfreightContext.SaveChangesAsync();

            pageModel.Input = new PreRegisterModel.InputModel {
                Email = "*****@*****.**", SenderId = "Test1234"
            };

            var result = (PageResult)pageModel.OnPost();

            Assert.IsNotNull(result);
            Assert.IsFalse(viewData.ModelState.IsValid);
            Assert.AreEqual(1, viewData.ModelState.Count);
            Assert.IsTrue(viewData.ModelState.ContainsKey("Input.SenderId"));
            Assert.IsTrue(viewData.ModelState.ErrorCount == 1);
            Assert.AreEqual("This Sender ID has already been registered. Ask your colleague to send you an invitation or contact helpdesk​", viewData.ModelState["Input.SenderId"].Errors[0].ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(PageResult));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _context.SenderType.AnyAsync(x => x.SenderId == SenderType.SenderId) ? _context.Update(SenderType) : _context.Add(SenderType);

            await _context.SaveChangesAsync();

            SuccessMessage = "Respondent details successfully saved";

            return(Page()); //RedirectToPage("/Dashboard");
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Msd2.CreatedDate = DateTime.Now;
            Msd2.CreatedBy   = _userManager.GetUserName(HttpContext.User);

            _context.Msd2.Add(Msd2);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        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);
        }
Ejemplo n.º 10
0
        public async Task OnPost_WhenEditingSenderType_ReturnsARedirectToPageResult()
        {
            var optionsBuilder = new DbContextOptionsBuilder <PortFreightContext>()
                                 .UseInMemoryDatabase("InMemoryDb")
                                 .Options;
            var context    = new PortFreightContext(optionsBuilder);
            var senderType = new SenderType()
            {
                SenderId = "Test5678",
                IsAgent  = true,
                IsLine   = false,
                IsPort   = false
            };
            await context.SenderType.AddAsync(senderType);

            await context.SaveChangesAsync();

            model.SenderIdPort = new SenderIdPort
            {
                SenderId = "Test5678",
                Locodes  = new List <string>
                {
                    "AAA123", "ABC456"
                }
            };

            model.SenderType = new SenderType
            {
                SenderId = "Test5678",
                IsAgent  = true,
                IsLine   = false,
                IsPort   = true
            };

            var result = (RedirectToPageResult)await model.OnPostAsync();

            Assert.IsNotNull(result);
            Assert.AreEqual("/Dashboard", result.PageName);
            Assert.IsInstanceOfType(result, typeof(RedirectToPageResult));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                if (GlobalPort.StatisticalPort == null && GlobalPort.CountryCode.ToUpper() == "GB")
                {
                    GlobalPort.StatisticalPort = GlobalPort.Locode;
                }

                bool alreadyExists = _context.GlobalPort.Any(x => x.PortName == GlobalPort.PortName);

                if (alreadyExists)
                {
                    ModelState.AddModelError("CustomError", "The Port Name already exists");
                }

                _context.GlobalPort.Add(GlobalPort);
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", e.InnerException.Message);

                _logger.LogError(e.Message);

                return(Page());
            }


            return(RedirectToPage("./Index", new { message = "Port added" }));
        }
        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"));
        }