Exemplo n.º 1
0
        public async Task <ActionResult <VehicleDutyDTO> > Create(CreatingVehicleDutyDTO dto)
        {
            try
            {
                var vehicleDuty = await vehicleDutyService.AddVehicleDuty(dto);

                return(CreatedAtAction(
                           nameof(GetById),
                           new { id = vehicleDuty.Id },
                           vehicleDuty
                           ));
            }
            catch (BusinessRuleValidationException ex)
            {
                return(BadRequest(new { Message = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public async Task <VehicleDutyDTO> AddVehicleDuty(CreatingVehicleDutyDTO vehicleDutyDTO)
        {
            List <Trip> trips = new List <Trip>();

            foreach (var tripID in vehicleDutyDTO.tripList)
            {
                var trip = await _tripRepository.GetByIdAsync(new TripId(tripID));

                trips.Add(trip);
            }

            var vehicleDuty = new VehicleDuty(
                vehicleDutyDTO.vehicleDutyCode,
                trips
                );

            var savedVehicleDuty = await this._vehicleDutyRepository.AddAsync(vehicleDuty);

            await this._unitOfWork.CommitAsync();

            return(_vehicleDutyMapper.DomainToDTO(savedVehicleDuty));
        }
Exemplo n.º 3
0
        private async Task <List <ImportedWorkBlockDTO> > ImportVehicleDutiesAndWorkblocks(XmlDocument doc, List <ImportedTripDTO> importedTrips)
        {
            string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("file", xmlns);

            var importedWorkBlockList = new List <ImportedWorkBlockDTO>();

            XmlNodeList vehicleDuties = doc.GetElementsByTagName("VehicleDuty");


            foreach (XmlNode vehicleDuty in vehicleDuties)
            {
                List <string> tripList = new List <string>();

                foreach (XmlNode refKey in vehicleDuty.ChildNodes[1].ChildNodes)
                {
                    string          keyString = refKey.Attributes["key"].Value;
                    ImportedTripDTO tripDTO   = getImportedTripFromKey(importedTrips, keyString);
                    if (tripDTO != null)
                    {
                        tripList.Add(tripDTO.Id.ToString());
                    }
                }

                string vdCode = vehicleDuty.Attributes["Name"].Value;

                CreatingVehicleDutyDTO cVDDTO = new CreatingVehicleDutyDTO(vdCode, tripList);

                var createdVDDTO = await this._vehicleDutyService.AddVehicleDuty(cVDDTO);

                XmlNodeList workblocksKeys = vehicleDuty.FirstChild.ChildNodes;

                List <WorkBlockDTO> cWBList = new List <WorkBlockDTO>();

                foreach (XmlNode workblockKey in workblocksKeys)
                {
                    string  key       = workblockKey.Attributes["key"].Value;
                    XmlNode workblock = doc.SelectSingleNode($"//file:WorkBlock[@key='{key}']", nsmgr);

                    List <string> wbTripList = new List <string>();
                    foreach (XmlNode refKey in workblock.FirstChild.ChildNodes)
                    {
                        string          keyString = refKey.Attributes["key"].Value;
                        ImportedTripDTO tripDTO   = getImportedTripFromKey(importedTrips, keyString);
                        if (tripDTO != null)
                        {
                            wbTripList.Add(tripDTO.Id.ToString());
                        }
                    }

                    string startingTime = TimeUtils.fromSecToString(Int32.Parse(workblock.Attributes["StartTime"].Value));
                    string endingTime   = TimeUtils.fromSecToString(Int32.Parse(workblock.Attributes["EndTime"].Value));

                    CreatingWorkBlockDTO cWBDTO = new CreatingWorkBlockDTO(wbTripList, startingTime, endingTime);
                    var wbDTO = await this._workBlockService.AddWorkBlock(cWBDTO);

                    cWBList.Add(wbDTO);
                    importedWorkBlockList.Add(new ImportedWorkBlockDTO(key, wbDTO));
                }

                VehicleDutyDTO createdVDDTOWithWorkBlocks = await this._vehicleDutyService.AddWorkBlocksToVehicleDuty(cWBList, new VehicleDutyId(createdVDDTO.Id));
            }
            return(importedWorkBlockList);
        }