public async void Post_Add_ValidModel_ReturnsCreated_ReturnsModel() { var path = $"{BaseUri}"; var dto = new DriverDto() { Id = Guid.NewGuid().ToString(), FirstName = "Driver5", Email = "*****@*****.**", LastName = "Taxi", CompanyId = "00000000-0000-0000-0000-000000000004", PhoneNumber = "0497635255", UserType = UserType.Driver }; var json = JsonConvert.SerializeObject(dto); var body = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(path, body); var content = await response.Content.ReadAsStringAsync(); var driver = JsonConvert.DeserializeObject <DriverDto>(content); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal(dto.Id, driver.Id); }
public async Task <IActionResult> AddNewDriver([FromBody] DriverDto newDriver) { var driver = _mapper.Map <Driver>(newDriver); var retVal = await _driverRepository.AddDriver(driver); return(Ok(retVal)); }
public async void Put_UpdateLocation_ValidModel_ReturnsOk_ReturnsDriver() { var path = $"{BaseUri}/UpdateLocation"; var dto = new DriverDto() { Id = "00000000-0000-0000-0000-000000000002", FirstName = "Driver1", LastName = "Taxi", Email = "*****@*****.**", PhoneNumber = "0498765432", CompanyId = "00000000-0000-0000-0000-00000000005", Latitude = 50, Longitude = 5 }; var json = JsonConvert.SerializeObject(dto); var body = new StringContent(json, Encoding.UTF8, "application/json"); var result = await _client.PutAsync(path, body); var content = await result.Content.ReadAsStringAsync(); var driver = JsonConvert.DeserializeObject <DriverDto>(content); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal(dto.Id, driver.Id); }
public int AddDriver([FromBody] DriverDto dto) { if (dto == null) { return(0); } Водитель driver = new Водитель() { ВнешнийХэш = dto.Hash, }; int?userId = dto.UserId; if (userId == null) { userId = new UserController().AddUser(dto.User); } driver.Пользователь = db.GetFromDatabase <Пользователь>(x => x.Id == userId).FirstOrDefault(); if (string.IsNullOrEmpty(driver.ВнешнийХэш)) { driver.ВнешнийХэш = HashHelper.GetHashForNewEntity(driver); } db.Insert(driver); return(driver.Id); }
public async Task <List <CarFullInfoDto> > GetCarsFullInfo(string model, string color) { var rawCars = CarDB.GetAllCars(); foreach (var each in rawCars) { System.Console.Out.WriteLine(model + " " + color); System.Console.Out.WriteLine(each.Model + " " + each.Color); } var cars = await Task.FromResult( rawCars .Where(car => car.Model.Equals(model) && car.Color.Equals(color)) .ToList() .ConvertAll <CarFullInfoDto>(car => { DriverDto driver = DriverDB[car.DriverId]; return(new CarFullInfoDto() { Id = car.Id, Color = car.Color, Model = car.Model, DriverId = car.DriverId, DriverAddress = driver.Address, DriverName = driver.Name }); } ) ); return(cars); }
public ResultDto Add([FromBody] DriverDto model) { if (!ModelState.IsValid) { return new ResultDto { Success = false, Message = "Não foi possível cadastrar a Motorista. Verifique se está preenchido corretamente." } } ; var driver = new Driver(model.DriverId, model.Name, model.Age, model.Sex, model.NationalDrivingLicense, model.HaveTruck); _repository.Add(driver); var resultDriverDto = new ResultDriverDto(driver.DriverId, driver.Name, driver.Age, driver.Sex, driver.NationalDrivingLicense, driver.HaveTruck); return(new ResultDto { Success = true, Message = "Motorista cadastrado com sucesso.", Data = resultDriverDto }); }
public void testSetParameters() { String mNumber = "12a45678b"; String name = "DriverTest"; DateTime birthDate = new DateTime(2000, 06, 14); int cardNumber = 12345678; int NIF = 987654321; int drivingLicense = 123456789; DateTime drivingLicenseExpirationDate = new DateTime(2024, 05, 01); List <String> DriverTypes = new List <String> { "Linguas", "Experiente" }; DateTime EntryDateCompany = new DateTime(2018, 07, 01); DateTime DepartureDateCompany = new DateTime(2019, 01, 01); DriverDto dto = new DriverDto(mNumber, name, birthDate, cardNumber, NIF, drivingLicense, drivingLicenseExpirationDate, DriverTypes, EntryDateCompany, DepartureDateCompany); Assert.AreEqual(dto.MechanographicNumber, mNumber); Assert.AreEqual(dto.Name, name); Assert.AreEqual(dto.DateBirth, birthDate); Assert.AreEqual(dto.CitizenCardNumber, cardNumber); Assert.AreEqual(dto.NIF, NIF); Assert.AreEqual(dto.DrivingLicenseNumber, drivingLicense); Assert.AreEqual(dto.DrivingLicenseExpirationDate, drivingLicenseExpirationDate); foreach (String s in DriverTypes) { Assert.IsNotNull(dto.DriverTypes.Contains(s)); } Assert.AreEqual(dto.EntryDateCompany, EntryDateCompany); Assert.AreEqual(dto.DepartureDateCompany, DepartureDateCompany); }
public bool SaveDriver(DriverDto driver) { using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); var query = "insert into pc_drivers(vehicletype,licenseno,typeoflicense,carno,firstname,address,city,state,phoneno,fareforkilometer,password,username,lastname) values(@vehicletype,@licenseno,@typeoflicense,@carno,@firstname,@address,@city,@state,@phoneno,@fareforkilometer,@password,@username,@lastname)"; //var query = "insert into pc_drivers(vehicletype,licenseno,typeoflicense,carno,firstname,address,city,state,phoneno,fareforkilometer,password,username,lastname) values(@vehicletype,@licenseno,@typeoflicense,@carno,@name,@address,@city,@state,@phoneno,@fareforkilometer,@password,@uname,@lname)"; //SqlCommand comm = new SqlCommand(query, conn); //comm.Parameters.AddWithValue("@name", driver.Firstname); //comm.Parameters.AddWithValue("@vehicletype", driver.Vehicletype); //comm.Parameters.AddWithValue("@licenseno", driver.Licenseno); //comm.Parameters.AddWithValue("@typeoflicense", driver.Typeoflicense); //comm.Parameters.AddWithValue("@carno", driver.Carno); //comm.Parameters.AddWithValue("@address", driver.Address); //comm.Parameters.AddWithValue("@city", driver.City); //comm.Parameters.AddWithValue("@state", driver.State); //comm.Parameters.AddWithValue("@phoneno", driver.Phoneno); //comm.Parameters.AddWithValue("@fareforkilometer", driver.Fareforkilometer); //comm.Parameters.AddWithValue("@password", driver.Password); //comm.Parameters.AddWithValue("@uname", driver.Username); //comm.Parameters.AddWithValue("@lname", driver.Lastname); var result = conn.Query<DriverDto>(query,driver); if (result !=null) { return true; } else { return false; } } }
public ResultDto Update([FromBody] DriverDto model) { if (!ModelState.IsValid) { return new ResultDto { Success = false, Message = "Não foi possível alterar os dados do motorista. Verifique se está preenchido corretamente." } } ; var update = new Driver(model.DriverId, model.Name, model.Age, model.Sex, model.NationalDrivingLicense, model.HaveTruck); _repository.Update(update); var resultDriverDto = new ResultDriverDto(update.DriverId, update.Name, update.Age, update.Sex, update.NationalDrivingLicense, update.HaveTruck); return(new ResultDto { Success = true, Message = "Dados atualizados com Sucesso!", Data = resultDriverDto }); } }
public async Task <IActionResult> GetAsync(string username) { DriverDto driver = await driverService.GetAsync(username); if (driver == null) { return(NotFound()); } return(Json(driver)); }
private void btnOK_Click(object sender, EventArgs e) { if (!ClientUtils.CheckEmpty(txtName, "EMPTY_DRIVER_NAME") || !ClientUtils.CheckEmpty(txtBigCar, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentBigCar, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtSmallCar, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentSmallCar, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtBigCarPick, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentBigCarPick, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtSmallCarPick, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentSmallCarPick, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtBigCarSend, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentBigCarSend, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtSmallCarSend, "EMPTY_FEE") || !ClientUtils.CheckEmpty(txtAgentSmallCarSend, "EMPTY_FEE")) { return; } int driverID = isModify ? selectedDriver.DriverID : 0; DriverDto param = new DriverDto { DriverID = driverID, DriverName = txtName.Text, Tel = txtTel.Text, Contact = txtContact.Text, BigCarFee = Convert.ToSingle(txtBigCar.Text), SmallCarFee = Convert.ToSingle(txtSmallCar.Text), AgentBigCarFee = Convert.ToSingle(txtAgentBigCar.Text), AgentBigCarPickAirportFee = Convert.ToSingle(txtAgentBigCarPick.Text), AgentBigCarSendAirportFee = Convert.ToSingle(txtAgentBigCarSend.Text), BigCarPickAirportFee = Convert.ToSingle(txtBigCarPick.Text), BigCarSendAirportFee = Convert.ToSingle(txtBigCarSend.Text), AgentSmallCarFee = Convert.ToSingle(txtAgentSmallCar.Text), AgentSmallCarPickAirportFee = Convert.ToSingle(txtAgentSmallCarPick.Text), AgentSmallCarSendAirportFee = Convert.ToSingle(txtAgentSmallCarSend.Text), SmallCarPickAirportFee = Convert.ToSingle(txtSmallCarPick.Text), SmallCarSendAirportFee = Convert.ToSingle(txtSmallCarSend.Text), Remark = txtRemark.Text, SupplierID = supplierID }; string strResult = WebCall.PostMethod <DriverDto>(isModify ? WebCall.ModifyDrivers: WebCall.AddDrivers, param); WebResult result = AppUtils.JsonDeserialize <WebResult>(strResult); if (result.Code.Equals(SystemConst.MSG_SUCCESS)) { ClientUtils.WarningCode(Travel.Client.Lang.LangBase.GetString(isModify ? "MODIFY_SUCCESS" : "ADD_SUCCESS") + result.Message); this.DialogResult = DialogResult.OK; this.Close(); } else { ClientUtils.WarningCode(result.Message); } }
public void ShowLastEvenResultWindow(ChampionshipDto championship) { var sessionCompletedViewmodel = _viewModelFactory.Create <SessionCompletedViewModel>(); (EventDto eventDto, SessionDto sessionDto) = championship.GetLastSessionWithResults(); var lastResult = sessionDto.SessionResult; if (lastResult == null) { return; } sessionCompletedViewmodel.Title = "Session Completed"; var podiumViewModel = _viewModelFactory.Create <PodiumViewModel>(); podiumViewModel.FromModel(lastResult); var driversFinishViewModel = _viewModelFactory.Create <SessionResultViewModel>(); driversFinishViewModel.Header = "Session Results"; driversFinishViewModel.FromModel(lastResult); var driversNewStandingsViewModel = _viewModelFactory.Create <DriversNewStandingsViewModel>(); driversNewStandingsViewModel.EventTitleViewModel.FromModel((championship, eventDto, sessionDto)); driversNewStandingsViewModel.EventTitleViewModel.ChampionshipName = "Current Standings"; driversNewStandingsViewModel.FromModel(lastResult); sessionCompletedViewmodel.Screens.Add(podiumViewModel); sessionCompletedViewmodel.Screens.Add(driversFinishViewModel); sessionCompletedViewmodel.Screens.Add(driversNewStandingsViewModel); if (championship.ChampionshipState == ChampionshipState.Finished) { DriverDto player = championship.Drivers.First(x => x.IsPlayer); if (player.Position <= 3) { var trophyViewModel = _viewModelFactory.Create <TrophyViewModel>(); trophyViewModel.Position = player.Position; trophyViewModel.DriverName = player.LastUsedName; sessionCompletedViewmodel.Screens.Add(trophyViewModel); } var championshipFinalStandings = _viewModelFactory.Create <StandingOverviewViewModel>(); championshipFinalStandings.Header = "Final Standing: "; championshipFinalStandings.FromModel(championship.Drivers.OrderBy(x => x.Position)); sessionCompletedViewmodel.Screens.Add(championshipFinalStandings); } Window window = _windowService.OpenWindow(sessionCompletedViewmodel, "Session Completed", WindowState.Maximized, SizeToContent.Manual, WindowStartupLocation.CenterOwner); sessionCompletedViewmodel.CloseCommand = new RelayCommand(() => CloseWindow(window)); }
public async Task <PopularResult <string> > UpdateAsync(DriverDto dto) { var result = new PopularResult <string>(); dto.Unit = null; var driver = ObjectMapper.Map <DriverDto, DriverEntity>(dto); await _driverRepository.UpdateAsync(driver); result.Success("更新成功"); return(result); }
public async Task <EventTripDetails> Handle(GetTripDetails request, CancellationToken cancellationToken) { var trip = _dbContext.EventTrips .Where(e => e.Id == request.Id) .Include(e => e.Driver) .Include(e => e.TripJoinRequests) .Include(e => e.Event) .AsNoTracking() .SingleOrDefault(); if (trip == null) { throw new NotFoundException(nameof(EventTrip), request.Id); } var driver = new DriverDto { Id = trip.Driver.Id, CarModel = trip.Driver.CarModel, Carplate = trip.Driver.Carplate, Name = trip.Driver.Name, Surname = trip.Driver.Surname, PhoneNumber = trip.Driver.PhoneNumber }; var tripJoinRequestIds = trip.TripJoinRequests.Select(x => x.Id); var tripJoinRequests = _dbContext.TripJoinRequests .Include(x => x.Passenger) .Where(x => tripJoinRequestIds.Contains(x.Id)) .Select(x => new TripJoinRequestDto { Address = x.Address, Approved = x.Approved, Id = x.Id, Passenger = new PassengerDto { Name = x.Passenger.Name, PhoneNumber = x.Passenger.PhoneNumber, Surname = x.Passenger.Surname } }); return(new EventTripDetails { DepartureAddress = trip.Address, EventAddress = trip.Event.Address, DepartureTime = trip.TripStartTime, Capacity = trip.Capacity, Driver = driver, EventName = trip.Event.EventName, TripJoinRequests = tripJoinRequests }); }
public IHttpActionResult UpdateDriver(DriverDto x) { try { d.updateDriver(x); return(Ok("success")); } catch { return(BadRequest("fds")); } }
public IHttpActionResult AddDriver(DriverDto x) { try { d.addDriver(x); return(Ok("pppp0")); } catch (Exception e) { return(BadRequest("fff")); } }
public async Task successful_driver_registration_based_on_username_and_user_id() { // Arrange string username = "******"; // Act HttpResponseMessage userResponse = await Client.GetAsync($"users/{username}"); // Assert userResponse.StatusCode.Should().BeEquivalentTo(HttpStatusCode.OK); // Act UserDto user = await GetDeserializedPayload <UserDto>(userResponse); // Assert Assert.Equal(user.Username, username); // Arrange CreateDriver.DriverVehicle vehicle = new CreateDriver.DriverVehicle { Brand = "Audi", Model = "A1", Color = "White", SeatingCapacity = 4 }; CreateDriver request = new CreateDriver { UserId = user.Id, Vehicle = vehicle }; // Act HttpContent payload = GetSerializedPayload(request); // Send POST request with the specified payload to server; path 'drivers/'. HttpResponseMessage response = await Client.PostAsync("drivers", payload); // Assert // Verify that the HTTP Post request was successful. // (HTTP response status code 201: Created) response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Created); // Vefify that the URI of the registered user. response.Headers.Location.ToString() .Should().BeEquivalentTo($"drivers/{request.UserId}"); // Act // Fetch a user with the specified email address. DriverDto driver = await GetUserAsync(request.UserId); // Assert // Verify that the user's email address is correct. driver.UserId.Should().Equals(request.UserId); }
public bool TryGetPointsForDriver(string driverName, out int points) { if (!_championshipEventController.IsChampionshipActive) { points = 0; return(false); } DriverDto driver = _championshipEventController.CurrentChampionship.Drivers.FirstOrDefault(x => x.LastUsedName == driverName); points = driver?.TotalPoints ?? 0; return(driver != null); }
// public async Task UpdateById(int id, Driver driver) // { // _context.Entry(driver).State = EntityState.Modified; // await _context.SaveChangesAsync(); // } public async Task UpdateById(int id, DriverDto driver) { var driverToUpdate = await _context.Drivers.SingleOrDefaultAsync(r => r.DriverId == id); if (driverToUpdate != null) { driverToUpdate.GivenName = driver.GivenName; driverToUpdate.Preposition = driver.Preposition; driverToUpdate.LastName = driver.LastName; driverToUpdate.DOB = driver.DOB; await _context.SaveChangesAsync(); } }
public IHttpActionResult UpdateDriver(DriverDto um) { try { ML.UpdateDriver(um); Console.WriteLine("dfd"); return(Ok("pppp0")); } catch (Exception e) { return(BadRequest(e.ToString())); } }
private Driver ToDriver(DriverDto driverDto, RaceResultDto raceResultDto) { if (driverDto.DriverCode != raceResultDto.DriverCode) { throw new ApplicationException("Driver code does not match."); } var name = new Name(driverDto.FirstName, driverDto.Surname); var code = new DriverCode(driverDto.DriverCode); var team = raceResultDto.Team; var finishStatus = new FinishStatus(new Position(raceResultDto.Position), raceResultDto.Status); return(new Driver(name, code, team, finishStatus)); }
public async Task <IHttpActionResult> GetDriver(int id) { DriverDto driver = await db.Drivers .Where(b => b.driverId == id) .Select(AsDriverDto) .FirstOrDefaultAsync(); if (driver == null) { return(NotFound()); } return(Ok(driver)); }
public async Task <PopularResult <string> > InsertAsync(DriverDto dto) { var result = new PopularResult <string>(); var entity = ObjectMapper.Map <DriverDto, DriverEntity>(dto); var driver = await _driverRepository.InsertAsync(entity); if (driver == null) { result.Failed("添加失败"); return(result); } result.Success("添加成功"); return(result); }
public IHttpActionResult CreateDriver(DriverDto driverDto) { if (!ModelState.IsValid) { return(BadRequest()); } var driver = Mapper.Map <DriverDto, Driver>(driverDto); _context.Drivers.Add(driver); _context.SaveChanges(); driverDto.Id = driver.Id; return(Created(new Uri(Request.RequestUri + "/" + driver.Id), driverDto)); }
public async void Put_ToggleAvailable_InvalidModel_ReturnsBadRequest() { var path = $"{BaseUri}/ToggleAvailable"; var dto = new DriverDto() { Id = "00000000-0000-0000-0000-00000000002", Latitude = 51.08619, Longitude = 2.97639 }; var json = JsonConvert.SerializeObject(dto); var body = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PutAsync(path, body); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public GrandPrixDriverDto MapDriver(ICarsRepository carsRepository, IDriversRepository driversRepository) { DriverDto driver = driversRepository.Get(driverId).Result.Map(); return(new GrandPrixDriverDto { team = team, carNumber = carNumber, driver = driver.firstName + " " + driver.lastName, car = carsRepository.Get(carId).Result.name, engine = engine, tyre = tyre, grid = grid, position = position, comment = comment }); }
private void modifyDriver() { if (dgDrivers.SelectedCells.Count == 0) { MessageBox.Show(LangBase.GetString("NOT_SELECT_DRIVER")); return; } else { int rowIndex = dgDrivers.SelectedCells[0].RowIndex; DriverDto driver = drivers[rowIndex]; AddDriver modifyTravelProject = new AddDriver(driver); if (modifyTravelProject.ShowDialog() == DialogResult.OK) { GetAllDrivers(); } } }
public async Task <ActionResult <DriverDto> > Update(int id, [FromBody] DriverDto driver) { if (id != driver.DriverId) { return(BadRequest()); } var driverObj = await _repo.GetById(id); if (driverObj == null) { return(NotFound()); } else { await _repo.UpdateById(id, driver); } return(NoContent()); }
public Driver getDriver(string NationalId) { if (ModelState.IsValid == false) { return(null); } NewApplicant applicant = context.NewApplicants.Where(w => w.NationalID == NationalId).FirstOrDefault(); Driver driver = context.Drivers.Where(d => d.NationalID == applicant.NationalID).FirstOrDefault(); DriverDto getdriver = new DriverDto() { Rate = driver.Rate, AvgRate = driver.AvgRate, numberOfTrips = driver.numberOfTrips, }; return(driver); }
public IActionResult New([FromBody] DriverDto dtoModle) { try { if (ModelState.IsValid) { _driverService.Insert(_mapper.Map <DriverModel>(dtoModle)); _driverService.ApplyChanges(); return(Ok()); } return(BadRequest(ModelState)); } catch (Exception ex) { return(StatusCode(500, ex.ToString())); throw; } }
public ActionResult AddNewDriver(DriverDto newDriver) { WebResult result = new WebResult { Code = SystemConst.MSG_ERR_UNKNOWN, Message = string.Empty }; using (var db = new TravelEntities()) { try { T_Drivers driver = new T_Drivers { DriverName = newDriver.DriverName, Tel = newDriver.Tel, Contact = newDriver.Contact, BigCarFee = newDriver.BigCarFee, SmallCarFee = newDriver.SmallCarFee, BigCarPickAirportFee = newDriver.BigCarPickAirportFee, SmallCarPickAirportFee = newDriver.SmallCarPickAirportFee, BigCarSendAirportFee = newDriver.BigCarSendAirportFee, SmallCarSendAirportFee = newDriver.SmallCarSendAirportFee, AgentBigCarFee = newDriver.AgentBigCarFee, AgentSmallCarFee = newDriver.AgentSmallCarFee, AgentBigCarPickAirportFee = newDriver.AgentBigCarPickAirportFee, AgentSmallCarPickAirportFee = newDriver.AgentSmallCarPickAirportFee, AgentBigCarSendAirportFee = newDriver.AgentBigCarSendAirportFee, AgentSmallCarSendAirportFee = newDriver.AgentSmallCarSendAirportFee, Remark = newDriver.Remark, SupplierID = newDriver.SupplierID }; db.T_Drivers.Add(driver); db.SaveChanges(); result.Code = SystemConst.MSG_SUCCESS; } catch (Exception exception) { result.Message = exception.Message; } return(Content(AppUtils.JsonSerializer(result))); } }
public ActionResult Create(FormCollection frm) { DriverDto driver = new DriverDto(); driver.Carno = frm["carnumber"]; driver.Address = frm["address"]; driver.City = frm["city"]; driver.Fareforkilometer = Convert.ToInt32(frm["fareforkilometer"]); driver.Licenseno = Convert.ToInt32(frm["licenseno"]); driver.Firstname = frm["fname"]; driver.Lastname = frm["lname"]; driver.Username = frm["uname"]; driver.Password = frm["password"]; driver.Phoneno = frm["phonenumber"]; driver.State = frm["state"]; driver.Typeoflicense = frm["licensetype"]; driver.Vehicletype = frm["vehicletype"]; DriverServices ds = new DriverServices(); ds.SaveDriver(driver); return View(); }
public bool SaveDriver(DriverDto driver) { var response = _driverServices.SaveDriver(driver); return response; }