コード例 #1
0
        protected override async Task OnParametersSetAsync()
        {
            _editContext = new EditContext(_tripFormModel);

            var result = int.TryParse(RunsheetId, out _id);

            _runsheet = await Unit.Runsheets.GetByIdAsync(_id);

            _activeTrip = await Unit.Trips.GetTripWithChildrenByRunsheetId(_id);

            if (_activeTrip != null)
            {
                _tripFormModel = TripMapper.MapTrip(_activeTrip, _tripFormModel);
            }

            if (_activeTrip == null)
            {
                _activeTrip = new Trip()
                {
                    InProgress = true
                };
                _tripFormModel.StartTime  = LocalTimeUtility.GetLocalTime();
                _tripFormModel.InProgress = true;
            }
        }
コード例 #2
0
        public async Task <ActionResult <TripDto> > Create(CreatingTripDto obj)
        {
            var dto  = TripMapper.toDTO(obj);
            var trip = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = trip.Id }, trip));
        }
コード例 #3
0
        private void btnAddTrip_Click(object sender, EventArgs e)
        {
            if (textBoxTrip.Text == string.Empty)
            {
                MessageBox.Show("Введены не все данные!");
                return;
            }
            TripMapper tm = new TripMapper();

            if (trip == null)
            {
                trip = new Trip(textBoxTrip.Text);
                try
                {
                    tm.Insert(trip);
                }
                catch (Exception ex)
                {
                    trip = null;
                    MessageBox.Show(ex.Message);
                    return;
                }
                if (formAddWayBill != null && formAddWayBill.Visible)
                {
                    if (formAddWayBill.insWayBill != null)
                    {
                        formAddWayBill.insWayBill.Trip = trip;
                    }
                    else
                    {
                        formAddWayBill.wayBill.Trip = trip;
                    }
                    formAddWayBill.textBoxTrip.Text = trip.Name;
                    this.Close();
                    return;
                }
            }
            else if (trip != null)
            {
                trip.Name = textBoxTrip.Text;
                try
                {
                    tm.Update(trip);
                }
                catch (Exception ex)
                {
                    trip = null;
                    MessageBox.Show(ex.Message);
                    return;
                }
                if (formForSelect != null && formForSelect.Visible)
                {
                    Form1.AddListTripInGrid(formForSelect.dataGridView);
                    this.Close();
                }
            }
            this.Close();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: RSGInc/Daysim-Actum
        public static void BeginExportTrips(string tripFilename, string outputPath)
        {
            List <ITrip> trips  = GetExportedTrips(tripFilename, (char)9);
            TripMapper   mapper = new TripMapper();

            var exporter = new TripSkimExporter(new TripSelector(), new VisumSkimTextWriter(outputPath), mapper);

            exporter.ExportTripsToSkims(trips);
        }
コード例 #5
0
        public async Task <TripDTO> CreateTrip(TripDTO tripModel)
        {
            Trip trip = TripMapper.ConvertModelToEntity(tripModel);

            if (await _tripRepo.CreateTrip(trip))
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
コード例 #6
0
        public async Task <TripDTO> GetTrip(int tripId)
        {
            var trip = await _tripRepo.GetTripById(tripId);


            if (trip != null)
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
コード例 #7
0
        private async Task UpdateModel()
        {
            _activeTrip = TripMapper.MapTrip(_tripFormModel, _activeTrip);
            _runsheet   = await Unit.Runsheets.GetByIdAsync(_id);

            if (_activeTrip.Id == 0)
            {
                _runsheet.Trips.Add(_activeTrip);
                await Unit.Runsheets.UpdateAsync(_runsheet);
            }
            else
            {
                await Unit.Trips.UpdateAsync(_activeTrip);
            }
        }
コード例 #8
0
        public async Task Post_AllParameters_Success()
        {
            CreatingTripDto request = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 });

            var mock = new Mock <ITripService>();

            mock.Setup(service => service.AddAsync(It.IsAny <TripDto>())).Returns(Task.FromResult(TripMapper.toDTO(request)));
            TripsController controller = new TripsController(mock.Object);

            var result = await controller.Create(request);

            mock.Verify(service => service.AddAsync(It.IsAny <TripDto>()), Times.AtLeastOnce());
            ActionResult <TripDto> tripDto = TripMapper.toDTO(request);

            Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>));
        }
コード例 #9
0
ファイル: TripMapperTest.cs プロジェクト: TiagoFBM/isep
        public void DTOtoDomain()
        {
            var mapper = new TripMapper();

            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            var expected = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);

            var actual = mapper.DomainToDTO(trip);

            Assert.True(expected.Equals(actual));
        }
コード例 #10
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingTripDto creatingTripDto = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 });

            TripDto tripDto        = TripMapper.toDTO(creatingTripDto);
            Trip    trip           = TripMapper.toDomain(tripDto);
            var     mockRepository = new Mock <ITripRepository>();

            mockRepository.Setup(repository => repository.AddAsync(It.IsAny <Trip>())).Returns(Task.FromResult(trip));

            var mockUnit = new Mock <IUnitOfWork>();

            TripService     TripService = new TripService(mockUnit.Object, mockRepository.Object);
            TripsController controller  = new TripsController(TripService);

            var result = await controller.Create(creatingTripDto);

            mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Trip>()), Times.AtLeastOnce());
            mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce());
            Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>));
        }
コード例 #11
0
        public async Task <TripDTO> PartialUpdateTrip(int tripId, JsonPatchDocument <TripDTO> patchDoc)
        {
            var trip = await _tripRepo.GetTripById(tripId);

            if (trip == null)
            {
                return(null);
            }

            TripDTO updatedTrip = TripMapper.ConvertEntityToModel(trip);

            patchDoc.ApplyTo(updatedTrip);

            trip = TripMapper.UpdateEntityFromModel(trip, updatedTrip);

            if (trip != null && await _tripRepo.UpdateTrip(trip))
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
コード例 #12
0
        public async Task <TripDTO> UpdateTrip(int tripId, TripDTO tripModel)
        {
            var trip = await _tripRepo.GetTripById(tripId);

            //upsert
            if (trip == null)
            {
                trip = new Trip()
                {
                    Id = tripId
                };
            }

            trip = TripMapper.UpdateEntityFromModel(trip, tripModel);

            if (trip != null && await _tripRepo.UpdateTrip(trip))
            {
                return(TripMapper.ConvertEntityToModel(trip));
            }

            return(null);
        }
コード例 #13
0
        public void testToDomain()
        {
            string key  = "keyTrip1";
            string line = "lineTest1";
            string path = "pathTest1";

            int[]      passingTimes  = { 1, 2, 3, 4, 5 };
            List <int> lPassingTimes = new List <int>();

            lPassingTimes.AddRange(passingTimes);

            Trip t          = new Trip(key, line, path, lPassingTimes);
            Trip mapperTrip = TripMapper.toDomain(TripMapper.toDTO(new CreatingTripDto(key, line, path, passingTimes)));

            Assert.AreEqual(t.Key, mapperTrip.Key);
            Assert.AreEqual(t.Line, mapperTrip.Line);
            Assert.AreEqual(t.Path, mapperTrip.Path);
            foreach (PassingTime pt in mapperTrip.PassingTimes)
            {
                Assert.IsNotNull(t.PassingTimes.Contains(pt));
            }
        }
コード例 #14
0
        public void testToDto()
        {
            string key  = "keyTrip1";
            string line = "lineTest1";
            string path = "pathTest1";

            int[]      passingTimes  = { 1, 2, 3, 4, 5 };
            List <int> lPassingTimes = new List <int>();

            lPassingTimes.AddRange(passingTimes);

            TripDto tdto      = new TripDto(key, line, path, lPassingTimes);
            TripDto mapperDto = TripMapper.toDTO(new CreatingTripDto(key, line, path, passingTimes));

            Assert.AreEqual(tdto.Key, mapperDto.Key);
            Assert.AreEqual(tdto.Line, mapperDto.Line);
            Assert.AreEqual(tdto.Path, mapperDto.Path);
            foreach (int i in mapperDto.PassingTimes)
            {
                Assert.IsNotNull(tdto.PassingTimes.Contains(i));
            }
        }
コード例 #15
0
 public TripService(ITripRepository repo, IUnitOfWork unitOfWork)
 {
     this._repo       = repo;
     this._unitOfWork = unitOfWork;
     this._mapper     = new TripMapper();
 }