예제 #1
0
        private void AddAirport(List <string> rowItems)
        {
            if (!_cityRepository.GetWhere(x => x.Name == rowItems[2].Trim('"')).Any())
            {
                _importInfoModel.SkippedRows++;
                return;
            }

            if (_airportRepository.Get(x => x.Id == int.Parse(rowItems[0])) == null)
            {
                var airport = new Airport
                {
                    Id                 = int.Parse(rowItems[0]),
                    Name               = rowItems[1].Trim('"'),
                    City               = rowItems[2].Trim('"'),
                    Country            = rowItems[3].Trim('"'),
                    IATA               = string.IsNullOrEmpty(rowItems[4]) || rowItems[4] == "\\N" ? null : rowItems[4].Trim('"'),
                    ICAO               = string.IsNullOrEmpty(rowItems[5]) || rowItems[5] == "\\N" ? null : rowItems[5].Trim('"'),
                    Latitude           = decimal.Parse(rowItems[6]),
                    Longitude          = decimal.Parse(rowItems[7]),
                    Altitude           = int.Parse(rowItems[8]),
                    Timezone           = ParserHelper.TryParseDouble(rowItems[9]),
                    DST                = rowItems[10].Trim('"'),
                    TzDatabaseTimezone = rowItems[11].Trim('"'),
                    Type               = rowItems[12].Trim('"'),
                    Source             = rowItems[13].Trim('"'),
                };
                _airportRepository.Add(airport);
                _importInfoModel.SuccessfullyImportedRows++;
            }
            else
            {
                _importInfoModel.SkippedRows++;
            }
        }
        public async Task <IActionResult> Add(AirportForAddDto airportForAdd)
        {
            if (!int.TryParse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty, out var userId))
            {
                return(Unauthorized());
            }

            var privilages = new List <int>()
            {
                (int)UserPrivileges.Administrator, (int)UserPrivileges.Employee
            };

            int.TryParse(User.FindFirst(ClaimTypes.Role)?.Value, out var privilagesId);

            if (!privilages.Contains(privilagesId))
            {
                return(StatusCode((int)HttpStatusCode.Unauthorized));
            }

            var airport = _mapper.Map <AirportEntity>(airportForAdd);

            var result = await _airportRepository.Add(airport);

            return(result ? Ok() : StatusCode((int)HttpStatusCode.InternalServerError));
        }
        public async Task <Airport> Handle(CreateAirportCommand request, CancellationToken cancellationToken)
        {
            var airport = _airportRepository.Add(new Airport(request.Code, request.Name));

            await _airportRepository.UnitOfWork.SaveEntitiesAsync();

            return(airport);
        }
예제 #4
0
        public ActionResult Save(Airport airport)
        {
            if (!ModelState.IsValid)
            {
                return(View("AirportForm", airport));
            }

            if (airport.AirportId == 0)
            {
                _areportrepository.Add(airport);
            }
            else
            {
                _areportrepository.Update(airport);
            }

            return(RedirectToAction("Index"));
        }
예제 #5
0
 public Task <bool> AddAirport(Airport airport)
 {
     _airportRepository.Add(airport);
     _airportRepository.Save();
     return(Task.FromResult(true));
 }
예제 #6
0
 public void CreateAirport(Airport airport)
 {
     _airportRepository.Add(airport);
     SaveAirport();
 }