コード例 #1
0
ファイル: DgtAppService.cs プロジェクト: okfiera/dgt
        /// <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>());
        }
コード例 #2
0
ファイル: DriverController.cs プロジェクト: TiagoFBM/isep
        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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
ファイル: FrmAttachDriver.cs プロジェクト: okfiera/dgt
        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);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
ファイル: ApiManagerDrivers.cs プロジェクト: okfiera/dgt
        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));
                    }
                }
            }
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        public async Task <IServiceResponse <bool> > UpateCaptain(int id, DriverDTO model)
        {
            return(await HandleApiOperationAsync(async() => {
                await _driverSvc.UpdateDriver(id, model);

                return new ServiceResponse <bool>(true);
            }));
        }
コード例 #12
0
        public async Task <IServiceResponse <bool> > AddDriver(DriverDTO driver)
        {
            return(await HandleApiOperationAsync(async() => {
                await _driverSvc.AddDriver(driver);

                return new ServiceResponse <bool>(true);
            }));
        }
コード例 #13
0
ファイル: DriverControllerTest.cs プロジェクト: TiagoFBM/isep
        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);
        }
コード例 #14
0
ファイル: DgtAppService.cs プロジェクト: okfiera/dgt
        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);
        }
コード例 #15
0
ファイル: DriverDSL.cs プロジェクト: gameflie/Simple-ERP
 public async Task <long> Save(DriverDTO entity)
 {
     try
     {
         return(await _driverDAL.Save(_mapper.Map <Driver>(entity)));
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
コード例 #16
0
 public IHttpActionResult Put(string id, [FromBody] DriverDTO driver)
 {
     try
     {
         DriverBL.UpdateDriver(id, driver);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
コード例 #17
0
ファイル: DriversController.cs プロジェクト: okfiera/dgt
 public IHttpActionResult Save(DriverDTO dto)
 {
     try
     {
         var result = this._dgtAppService.AddNewDriver(dto);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
コード例 #18
0
 public IHttpActionResult Post([FromBody] DriverDTO driver)
 {
     try
     {
         DriverBL.Add(driver);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
コード例 #19
0
        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();
        }
コード例 #20
0
 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
     });
 }
コード例 #21
0
ファイル: DriverServiceTest.cs プロジェクト: TiagoFBM/isep
        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);
        }
コード例 #22
0
        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));
            }
        }
コード例 #23
0
        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();
        }
コード例 #24
0
        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));
            }
        }
コード例 #25
0
ファイル: DriverController.cs プロジェクト: matimoreira/cocou
        public ActionResult Delete(DriverDTO driver)
        {
            var dao = new DriverDAO();
            var PudoEliminarElregistro = dao.Delete(driver);

            if (PudoEliminarElregistro)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("todo mal"));
            }
        }
コード例 #26
0
        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)));
        }
コード例 #27
0
        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();
        }
コード例 #28
0
        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();
        }
コード例 #29
0
 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);
     }
 }
コード例 #30
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);
        }