public async Task <DriverViewModel> CreateDriver(DriverInputModel driverInputModel) { var walletId = await this.walletService.CreateWallet(driverInputModel.ApplicationUserId); var driver = new Driver() { ApplicationUserId = driverInputModel.ApplicationUserId, Comission = 20, DocumentConfirmation = false, CurrentLocation = driverInputModel.CurrentLocation, Referal = Guid.NewGuid().ToString(), ReferalUsedTimes = 0, WalletId = walletId, CreatedOn = DateTime.UtcNow }; //TODO: rEF this.repository.Add(driver); var result = await this.repository.SaveChangesAsync(); return(result > 0 ? new DriverViewModel() { Comission = driver.Comission, DocumentConfirmatiom = driver.DocumentConfirmation, Id = driver.Id } : null); }
public async Task <IActionResult> Post([FromBody] DriverInputModel input) { if (!this.ModelState.IsValid || input == null) { return(this.ValidationProblem()); } var driver = await this.driverService.CreateDriver(input); if (driver == null) { return(this.BadRequest()); } var r = await this.accountService.AddDriverSettings(input.ApplicationUserId, driver.Id); if (r) { await this.hub.Clients.All.BroadcastMessage(); return(this.Content(driver.Id)); } return(this.BadRequest()); }
public async Task <IActionResult> Register(DriverInputModel input) { if (!ModelState.IsValid) { return(this.View()); } await this.driversService.AddDriverAsync(input); return(this.RedirectToAction(nameof(DriverAdded), "Drivers", new ChangesApplied { Message = Driver_Added })); }
public async Task AddDriverAsync(DriverInputModel input) { var currDriver = new ApplicationUser { Email = input.Email, UserName = input.Email, FirstName = input.FirstName, LastName = input.LastName, PhoneNumber = input.PhoneNumber }; var result = await this.userManager.CreateAsync(currDriver, input.Password); if (result.Succeeded) { await this.userManager.AddToRoleAsync(currDriver, Driver_RoleName); } }
public async Task <IActionResult> Create(DriverInputModel driverInputModel) { if (!this.ModelState.IsValid) { return(this.View(driverInputModel)); } var driverServiceModel = driverInputModel.To <DriverServiceInputModel>(); var imageUrl = await this.cloudinaryService.UploadImageAsync( driverInputModel.Image, $"{driverServiceModel.FirstName}-{driverServiceModel.LastName}", GlobalConstants.DriversImagesFolder); driverServiceModel.Image = imageUrl; await this.driversService.CreateAsync(driverServiceModel); return(this.Redirect("/Administration/Drivers/All")); }
public async Task AddDriverShouldCreateNewDriverInDbAndPutItToDriverRole() { List <ApplicationUser> _users = new List <ApplicationUser>(); var input = new DriverInputModel() { Email = "*****@*****.**", Password = "******", FirstName = "Pesho", LastName = "Ivanov", PhoneNumber = "0888-123-456" }; var input1 = new DriverInputModel() { Email = "*****@*****.**", Password = "******", FirstName = "Gosho", LastName = "Ivanov", PhoneNumber = "0888-123-456" }; var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); UserManager <ApplicationUser> _userManager = MockUserManager <ApplicationUser>(_users).Object; var driversService = new DriversService(db, _userManager); await driversService.AddDriverAsync(input); await driversService.AddDriverAsync(input1); int result = _users.Count; string resultFirstName = _users.FirstOrDefault(u => u.FirstName == "Pesho").FirstName; Assert.Equal(2, result); Assert.Equal("Pesho", resultFirstName); }