/// <summary> /// <see cref="IDgtAppService"/> /// </summary> /// <returns><see cref="IDgtAppService"/></returns> public DriverDTO AddNewDriver(DriverDTO driverDTO) { if (driverDTO == null) { throw new ArgumentNullException("driverDTO"); } // Check driver identifier is unique var identifierSpec = DriverSpecifications.WithIdentifier(driverDTO.Identifier); var repeatedIdentifierDriver = _driverRepository.AllMatching(identifierSpec); if (repeatedIdentifierDriver != null && repeatedIdentifierDriver.Any()) { throw new InvalidOperationException(String.Format(CommonMessages.exception_ItemAlreadyExistsWithProperty, Names.Driver, Names.Identifier, driverDTO.Identifier)); } // Cast dto to driver and save var driver = MaterializeDriverFromDto(driverDTO); // Set initial points for new drivers driver.SetInitialPoints(); driver.GenerateNewIdentity(); driver.CreatedDate = DateTime.Now; driver.Validate(); _driverRepository.Add(driver); _driverRepository.UnitOfWork.Commit(); return(driver.ProjectedAs <DriverDTO>()); }
public async Task <ActionResult <FullDriverDTO> > GetById(Guid id) { List <DriverTypeDTO> listDriverTypes = new List <DriverTypeDTO>(); List <FullDriverDTO> listFullDrivers = new List <FullDriverDTO>(); DriverDTO driverDTO = await driverService.GetById(new DriverID(id)); foreach (var driverTypeDTO in driverDTO.driverTypes) { DriverTypeDTO driverType = await driverTypeService.GetDriverTypeByID(driverTypeDTO); listDriverTypes.Add(driverType); } FullDriverDTO fullDriverDTO = new FullDriverDTO(driverDTO.Id, driverDTO.mecanographicNumber, driverDTO.citizenCardDTO, driverDTO.entranceDate, driverDTO.departureDate, driverDTO.driverLicense, listDriverTypes); listFullDrivers.Add(fullDriverDTO); if (fullDriverDTO == null) { return(NotFound()); } return(fullDriverDTO); }
/// <summary> add a new driver in the db /// </summary> public static void Add(DriverDTO driver) { UserDTO u = UserBL.Add(driver); driver.Identity = u.Identity; DriverDal.AddDriver(Converters.DriverConverters.GetDriver(driver)); }
private async void GetDriverByIdentifier(string identifier) { if (!String.IsNullOrEmpty(identifier)) { var result = await ApiManagerDrivers.GetByNifNie(identifier); if (result != null) { this.driverDTOBindingSource.DataSource = result; this.driverDTO = result; this.cmdAccept.Enabled = true; this.cmdAccept.Focus(); } else { this.driverDTO = null; this.driverDTOBindingSource.Clear(); this.cmdAccept.Enabled = false; MessageBox.Show("No se ha encontrado ningún Conductor con el NIF/NIE " + identifier, "Añadir conductor habitual", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { this.cmdAccept.Enabled = false; MessageBox.Show("Debes introducir el NIF/NIE del conductor", "Añadir conductor habitual", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public bool Update(string token, DriverDTO driverDTO) { using (var uow = new UnitOfWork(new RaceManagerDbContext())) { if (!AuthorizationManager.Instance.Authorize(uow, token)) { return(false); } var driver = uow.Drivers.Get(driverDTO.Id); if (driver == null) { return(false); } driver.FirstName = driverDTO.FirstName; driver.LastName = driverDTO.LastName; driver.UMCN = driverDTO.UMCN; if (!uow.Complete()) { return(false); } return(true); } }
public void DriverDTO_Test() { // Act DriverDTO driverDTO = Mapper.Map <DriverDTO>(driver); CarDTO carDTO = Mapper.Map <CarDTO>(driver.Car); Driver testDriver = Mapper.Map <Driver>(driverDTO); Car testCar = Mapper.Map <Car>(driverDTO.SelectedCar); //Assert Assert.AreEqual(driver.Id, driverDTO.UserId); Assert.AreEqual(driver.ControllerId, driverDTO.ControllerId); Assert.AreEqual(driver.ApplicationUser.ImageName, driverDTO.ImageName); Assert.AreEqual(driver.ApplicationUser.UserName, driverDTO.UserName); Assert.AreEqual(carDTO.Id, driverDTO.SelectedCar.Id); Assert.AreEqual(carDTO.RecordHolder, driverDTO.SelectedCar.RecordHolder); Assert.AreEqual(carDTO.ImageName, driverDTO.SelectedCar.ImageName); Assert.AreEqual(carDTO.TrackRecord, driverDTO.SelectedCar.TrackRecord); Assert.AreEqual(driver.ControllerId, testDriver.ControllerId); Assert.AreEqual(driver.ApplicationUser.ImageName, testDriver.ApplicationUser.ImageName); Assert.AreEqual(carDTO.Id, testDriver.Car.Id); // Assert.AreEqual(carDTO.RecordHolder, testDriver.Car.BestLapTime.ApplicationUser.UserName); Assert.AreEqual(carDTO.ImageName, testDriver.Car.ImageName); // Assert.AreEqual(carDTO.TrackRecord, testDriver.Car.BestLapTime.LapTime.Time); Assert.AreEqual(driver.ApplicationUser.UserName, testDriver.ApplicationUser.UserName); }
public void ShouldThrowExceptionWhenReturningCarWithEarlierStopTimeThanStartTime() { var driver = new DriverDTO { Id = new Guid(), FirstName = "Mikołaj", LastName = "Fitowski", LicenseNumber = "CDJ813" }; TestContainer.DriverService.CreateDriver(driver); var rentalArea = Helper.CreateRentalAreaDTO(); TestContainer.RentalAreaService.CreateRentalArea(rentalArea); var car = new CarDTO { Id = new Guid(), RegistrationNumber = "KR12345", RentalAreaId = rentalArea.Id, CurrentLatitude = 50.057236, CurrentLongitude = 19.945147 }; TestContainer.CarService.CreateCar(car); var rentalId = new Guid(); var startTime = new DateTime(2020, 04, 19); TestContainer.RentalService.TakeCar(rentalId, car.Id, driver.Id, startTime); var stopTime = new DateTime(2020, 04, 18); Assert.Throws <Exception>(() => TestContainer.RentalService.ReturnCar(rentalId, stopTime)); }
public static async Task <DriverDTO> AddNew(DriverDTO driver) { using (var client = GetHttpClient()) { var serializeObject = JsonConvert.SerializeObject(driver); var content = new StringContent(serializeObject, Encoding.UTF8, "application/json"); using (var response = await client.PostAsync(URL_KEY + "/save", content)) { if (response.IsSuccessStatusCode) { if (response.Content != null) { var stringResult = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <DriverDTO>(stringResult); return(result); } else { return(null); } } else { //Logger.Error("Error creando {0} '{1}'.", syncEntity.Singular(), obj.Name); throw new Exception(await CastResultError(response)); } } } }
public ActionResult Create(DriverDTO dto) { var driver = new Driver(); driver.Contact = dto.Contact; driver.CNIC = dto.CNIC; driver.Email = dto.Email; driver.Address = dto.Address; driver.Name = dto.Name; driver.LicenseNumber = dto.LicenseNumber; driver.CabNumber = dto.CabNumber; try { db.Drivers.Add(driver); db.SaveChanges(); if (driver.Id != 0) { TempData["UserMessages"] = "Driver Succesfully Created."; return(RedirectToAction("Index", "driver")); } else { TempData["error"] = "Driver Succesfully Created." + "Error Message"; return(RedirectToAction("Create", "Driver")); } } catch (Exception e) { TempData["error"] = "Driver Succesfully Created." + "Error Message" + e; } return(RedirectToAction("Create", "Driver")); }
public async Task <IActionResult> PostDriver([FromBody] DriverDTO driverDTO) { var driver = _mapper.Map <DriverDTO, Driver>(driverDTO); var NewDriver = _unitOfWork.Driver.Add(driver); await _unitOfWork.SaveAsync(); return(CreatedAtAction(nameof(GetDriver), new { id = NewDriver.DriverId }, NewDriver)); }
public async Task <IServiceResponse <bool> > UpateCaptain(int id, DriverDTO model) { return(await HandleApiOperationAsync(async() => { await _driverSvc.UpdateDriver(id, model); return new ServiceResponse <bool>(true); })); }
public async Task <IServiceResponse <bool> > AddDriver(DriverDTO driver) { return(await HandleApiOperationAsync(async() => { await _driverSvc.AddDriver(driver); return new ServiceResponse <bool>(true); })); }
public async void create() { var driverServiceMock = new Mock <IDriverService>(); var driverTypeServiceMock = new Mock <IDriverTypeService>(); 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>() { 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 driverTypeDTO = new DriverTypeDTO("driverType1", "Teste"); 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); driverTypeServiceMock.Setup(_ => _.GetDriverTypeByID("driverType1")).ReturnsAsync(driverTypeDTO); driverServiceMock.Setup(_ => _.AddDriver(creatingDriverDTO, creatingLicenseDTO, creatingCitizenCardDTO)).ReturnsAsync(driverDTO); var controller = new DriverController(driverServiceMock.Object, driverTypeServiceMock.Object); var actual = await controller.Create(creatingDriverDTO); Assert.NotNull(actual); Assert.NotNull(actual.Result); }
private Driver MaterializeDriverFromDto(DriverDTO dto) { var driver = DriverFactory.CreateDriver(dto.Identifier, dto.FirstName, dto.LastName, dto.Points); if (dto.Id != Guid.Empty) { driver.ChangeCurrentIdentity(dto.Id); } return(driver); }
public async Task <long> Save(DriverDTO entity) { try { return(await _driverDAL.Save(_mapper.Map <Driver>(entity))); } catch (Exception ex) { return(0); } }
public IHttpActionResult Put(string id, [FromBody] DriverDTO driver) { try { DriverBL.UpdateDriver(id, driver); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult Save(DriverDTO dto) { try { var result = this._dgtAppService.AddNewDriver(dto); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] DriverDTO driver) { try { DriverBL.Add(driver); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public void UpdateDriver(DriverDTO driverDto) { var driver = _unitOfWork.DriverRepository.Find(d => d.Id == driverDto.Id) .FirstOrDefault(); if (driver == null) { throw new Exception($"Driver with {driverDto.Id} was not found"); } MapDtoToDriver(driverDto, driver); _unitOfWork.Commit(); }
public DriverViewModel Map(DriverDTO driver) { return(new DriverViewModel { Id = driver.Id, FirstName = driver.FirstName, LastName = driver.LastName, LicenseNumber = driver.LicenseNumber, DriverStatus = driver.DriverStatus, FreeMinutesPolicy = driver.FreeMinutesPolicy }); }
public async void GetAllTest() { 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 driversDTO = new List <DriverDTO>() { driverDTO }; var drivers = new List <Driver>() { driver }; repo.Setup(_ => _.GetAllAsync()).ReturnsAsync(drivers); var driverService = new DriverService(repo.Object, uow.Object); var actual = await driverService.GetAll(); Assert.Equal(driversDTO, actual); }
public async Task <IHttpActionResult> Add([FromBody] DriverDTO model) { if (ModelState.IsValid) { var result = await _driversService.Add(model); return(result.IsSuccess ? StatusCode(HttpStatusCode.NoContent) : (IHttpActionResult)BadRequest(result.Error)); } else { return(BadRequest(ModelState)); } }
public void CreateDriver(DriverDTO driverDTO) { Expression <Func <Driver, bool> > expressionPredicate = x => x.LicenceNumber == driverDTO.LicenceNumber; Driver driver = this._unitOfWork.DriverRepository.Find(expressionPredicate).FirstOrDefault(); if (driver != null) { throw new Exception($"Driver with: '{driver.LicenceNumber}' licence number already exists"); } driver = new Driver(driverDTO.DriverId, driverDTO.FirstName, driverDTO.LastName, driverDTO.LicenceNumber, driverDTO.FreeMinutes, this._domainEventPublisher); this._unitOfWork.DriverRepository.Insert(driver); this._unitOfWork.Commit(); }
public async Task <Result> Add(DriverDTO model) { try { await _repository.Add(_mapper.Map <DriverDAL>(model)); return(Result.Success()); } catch (OleDbException e) { return(Result.Failure <IEnumerable <DriverDTO> >(e.Message)); } }
public ActionResult Delete(DriverDTO driver) { var dao = new DriverDAO(); var PudoEliminarElregistro = dao.Delete(driver); if (PudoEliminarElregistro) { return(Ok()); } else { return(BadRequest("todo mal")); } }
public void ShouldThrowExceptionIfAddDriverWithNoLastName() { //assign var driver = new DriverDTO { Id = new Guid(), FirstName = "Mikołaj", LicenseNumber = "CDJ813" }; //act //assert Assert.Throws <Exception>((() => TestContainer.DriverService.CreateDriver(driver))); }
public void CreateDriver(DriverDTO driverDto) { var driver = _unitOfWork.DriverRepository.Find(d => d.LicenseNumber == driverDto.LicenseNumber) .FirstOrDefault(); if (driver != null) { throw new Exception($"Driver with {driverDto.LicenseNumber} license number already exists."); } driver = _driverFactory.Create(driverDto.Id, driverDto.LicenseNumber, driverDto.FirstName, driverDto.LastName); _unitOfWork.DriverRepository.Insert(driver); _unitOfWork.Commit(); }
public async Task AddDriver(DriverDTO driver) { driver.Code = driver.Code.Trim(); if (await _driverRepo.ExistAsync(v => v.Code == driver.Code)) { throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DRIVER_EXIST); } var walletNumber = await _walletSvc.GenerateNextValidWalletNumber(); _walletNumberRepo.Insert(walletNumber); var wallet = new Wallet { WalletNumber = walletNumber.WalletPan, CreatorUserId = _serviceHelper.GetCurrentUserId(), Balance = 0.00M, UserType = UserType.Captain.ToString() }; _walletSvc.Add(wallet); _driverRepo.Insert(new Driver { Code = driver.Code, CreatorUserId = _serviceHelper.GetCurrentUserId(), DriverStatus = driver.DriverStatus, DriverType = driver.DriverType, HandoverCode = driver.HandoverCode, Name = driver.Name, Phone1 = driver.Phone1, Phone2 = driver.Phone2, Designation = driver.Designation, AssignedDate = driver.AssignedDate, ResidentialAddress = driver.ResidentialAddress, NextOfKin = driver.NextOfKin, Picture = driver.Picture, Active = true, NextOfKinNumber = driver.NextOfKinNumber, BankName = driver.BankName, BankAccount = driver.BankAccount, DeactivationReason = driver.DeactivationReason, WalletId = wallet.Id, NoOfTrips = 0, DateOfEmployment = driver.DateOfEmployment }); await _unitOfWork.SaveChangesAsync(); }
public async Task <long> Save(DriverDTO entity) { try { if (entity.Id > 0) { await _accountingSharedDSL.UpdateAccountName(entity.Id, entity.FullName); } return(await _driverDAL.Save(_mapper.Map <Driver>(entity))); } catch (Exception ex) { return(0); } }
public Guid CreateDriver(string licenseNumber, string firstName, string lastName, int freeMinutes) { Guid driverId = Guid.NewGuid(); DriverDTO driverDTO = new DriverDTO() { Id = driverId, LicenseNumber = licenseNumber, FirstName = firstName, LastName = lastName, FreeMinutes = freeMinutes, }; this._driverService.CreateDriver(driverDTO); return(driverId); }