예제 #1
0
        public IActionResult ApproveEditInfoRequest(Guid requestId)
        {
            try
            {
                var request = EditInfoRequestService.GetById(requestId);
                var driver  = DriverService.GetById(request.Applicant);
                DriverService.UpdateDriver(driver, request.NewName, request.NewEmail);

                var user = UserManager.GetUserAsync(User).GetAwaiter().GetResult();
                EditInfoRequestService.ApproveRequest(request, user.Id);
                var driverAccount = UserManager.FindByEmailAsync(request.OldEmail).GetAwaiter().GetResult();
                driverAccount.UserName    = request.NewName;
                driverAccount.Email       = request.NewEmail;
                driverAccount.PhoneNumber = request.NewPhoneNumber;
                UserManager.UpdateAsync(driverAccount).GetAwaiter().GetResult();

                return(RedirectToAction("EditInfoRequestsPartial"));
            }
            catch (Exception e)
            {
                Logger.LogDebug("Failed to approve request {@Exception}", e);
                Logger.LogError("Failed to approve request {Exception}", e.Message);
                return(BadRequest("Failed to approve request "));
            }
        }
예제 #2
0
        public async void GetByIdTest()
        {
            var repo = new Mock <IDriverRepository>();
            var uow  = new Mock <IUnitOfWork>();

            string mecanographicNumber = "D-103";
            string driverName          = "Driver Teste";
            string birthDate           = "12/12/1971";
            long   citizenCardNumber   = 11144477;
            long   driverNIF           = 159951159;
            string entranceDate        = "27/01/1978";
            string departureDate       = "31/05/2020";
            string numberDriverLicense = "P-1111111 1";
            string dateDriverLicense   = "12/10/2020";

            var driverType = new DriverTypeId("driverType1");

            List <DriverTypeId> listDriverTypes = new List <DriverTypeId>();

            listDriverTypes.Add(driverType);

            var driver = new Driver(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, listDriverTypes);

            CitizenCardDTO citizenCardDTO = new CitizenCardDTO(driver.citizenCard.Id.AsGuid(), driverName, birthDate, citizenCardNumber, driverNIF);

            LicenseDTO licenseDTO = new LicenseDTO(driver.driverLicense.Id.AsGuid(), numberDriverLicense, dateDriverLicense);

            List <string> driverTypeDTOs = new List <string>()
            {
                driverType.id
            };

            var driverDTO = new DriverDTO(driver.Id.AsGuid(), mecanographicNumber, citizenCardDTO, entranceDate, departureDate, licenseDTO, driverTypeDTOs);

            repo.Setup(_ => _.GetByIdAsync(driver.Id)).ReturnsAsync(driver);

            var driverService = new DriverService(repo.Object, uow.Object);

            var actual = await driverService.GetById(driver.Id);

            Assert.Equal(driverDTO, actual);
        }