Exemplo n.º 1
0
        public async Task <ActionResult> AddDriver(Driver driver)
        {
            await CreateRoles();
            await createadmin();

            if (ModelState.IsValid)
            {
                var driverModel = await driversRepo.addDriver(driver);

                if (driverModel != null)
                {
                    if (await roleManager.RoleExistsAsync("Driver"))
                    {
                        await userManager.AddToRoleAsync(driverModel, "Driver");
                    }

                    var message = new Message(new string[] { driver.Email }, "Welcome to tracker application",
                                              $" Dear {driverModel.UserName} welcome \n   This is your password : {driver.Password}");
                    emailSender.SendEmail(message);
                    return(Ok(driver));
                }
                return(BadRequest());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddDriver(Driver driver)
        {
            if (ModelState.IsValid)
            {
                await _idriverrepo.addDriver(driver);

                return(Ok(driver));
            }
            else
            {
                return(BadRequest());
            }
        }