Esempio n. 1
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));
        }
Esempio n. 2
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());
        }