Пример #1
0
        public static async Task <string> AddDriverItem(Driver driver)
        {
            var driverService = new DriverService();
            var response      = await driverService.AddDriver(driver);

            return(response.ToString());
        }
Пример #2
0
        public async void AddDriver()
        {
            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);

            var creatingDriverDTO = new CreatingDriverDTO(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, driverTypeDTOs);

            var creatingCitizenCardDTO = new CreatingCitizenCardDTO(driverName, birthDate, citizenCardNumber, driverNIF);

            var creatingLicenseDTO = new CreatingLicenseDTO(numberDriverLicense, dateDriverLicense);

            repo.Setup(_ => _.AddAsync(driver)).ReturnsAsync(driver);

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

            var actual = await service.AddDriver(creatingDriverDTO, creatingLicenseDTO, creatingCitizenCardDTO);

            Assert.Equal(driverDTO, actual);
        }
        public async Task <ActionResult> RegisterDriver(RegisterDriverViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email, IsDriver = model.IsDriver
                    };
                    var result = UserManager.Create(user, model.Password);
                    if (result.Succeeded)
                    {
                        var           roleResult    = UserManager.AddToRole(user.Id, "Driver");
                        DriverService driverService = new DriverService();
                        driverService.AddDriver(user.Id, !String.IsNullOrEmpty(model.LicenceRegistrationDate) ? Convert.ToDateTime(model.LicenceRegistrationDate) : DateTime.Now.AddYears(-18), DateTime.Now);
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return(RedirectToAction("EmailNotConfirmed", "Account"));
                    }
                    AddErrors(result);
                }
                catch (Exception ex)
                {
                    var t = ex.Message;
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public void AddDriver([FromBody] Driver op)
 {
     service.AddDriver(op);
 }