Пример #1
0
        public async Task <LaunchDto?> SaveLaunch(LaunchDto dto)
        {
            try
            {
                Task <HttpResponseMessage>?saveTask;
                var content = _serviceResponseHandler.BuildJsonContent(dto);
                if (dto.LaunchId == 0)
                {
                    saveTask = _httpClient.PostAsync("api/Launches", content);
                }
                else
                {
                    saveTask = _httpClient.PutAsync("api/Launches", content);
                }

                var response = await saveTask;
                return(await _serviceResponseHandler.HandleJsonResponse <LaunchDto>(response));
            }
            catch (AccessTokenNotAvailableException exception)
            {
                exception.Redirect();
            }

            return(null);
        }
Пример #2
0
        public ActionResult <LaunchDto> Launch(string year)
        {
            var result = _launchService.GetProjectsByLaunchYear(year);

            if (result.IsSuccess)
            {
                var launchDto = new LaunchDto(result.Value.First());
                return(Ok(launchDto));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task AddLaunchesToDbIfNotExist(IList <LaunchDto> launches)
        {
            List <LaunchDto> launchesToDb = new List <LaunchDto>();

            foreach (LaunchDto launch in launches)
            {
                LaunchDto existLaunch = await _context.Launches.FirstOrDefaultAsync(l => l.Id == launch.Id);

                if (existLaunch == null)
                {
                    await _context.AddAsync(launch);
                    await SaveChangesAsync();
                }
            }
        }
        public async Task <int> AddLaunchToDbIfNotExist(LaunchDto launch)
        {
            LaunchDto existLaunch = await _context.Launches.FirstOrDefaultAsync(l => l.LaunchNumber == launch.LaunchNumber);

            if (existLaunch == null)
            {
                await _context.AddAsync(launch);
                await SaveChangesAsync();

                return(launch.Id);
            }
            else
            {
                return(existLaunch.Id);
            }
        }
        private async Task <IActionResult?> SaveRocket(LaunchDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(CreateResponse(new BaseServiceResponse <LaunchDto>(dto, System.Net.HttpStatusCode.BadRequest)));
            }

            using (var transaction = await DBContext.Database.BeginTransactionAsync())
            {
                var service  = GetService <LaunchesCreateUpdate>();
                var response = await service.SaveLaunch(dto);

                transaction.Commit();

                return(CreateResponse(response));
            }
        }
Пример #6
0
        private LaunchDto ConvertLaunchLibraryLaunchModelToDto(LibraryLaunchModel launch, CountryDto country, AgencyDto agency)
        {
            var launchDto = new LaunchDto
            {
                LaunchNumber   = launch.LaunchId,
                MissionName    = launch.LaunchName,
                LaunchDate     = DateTime.ParseExact(launch.LaunchTime, "MMMM d, yyyy HH:mm:ss UTC", CultureInfo.InvariantCulture),
                LaunchSite     = launch.Location.LocationName,
                RocketName     = launch.Rocket.RocketName,
                MissionDetails = launch.Missions?.FirstOrDefault()?.MissionDescription,
                InfoUrl        = launch.Location?.Pads?.FirstOrDefault()?.InfoUrl,
                ChangedTime    = DateTime.Now,
                UpdatedTime    = DateTime.UtcNow,
                Country        = country,
                Agency         = agency
            };

            return(launchDto);
        }
Пример #7
0
        // LaunchDto (ExternalLaunchModel)
        private LaunchDto ConvertSpaceXLaunchToDto(SpaceXLaunchModel launch, CountryDto country, AgencyDto agency)
        {
            var launchDto = new LaunchDto
            {
                LaunchNumber   = launch.FlightId,
                MissionName    = launch.MissionName,
                LaunchDate     = launch.LaunchDateUtc,
                LaunchSite     = launch.LaunchSite.SiteNameLong,
                RocketName     = launch.Rocket.RocketName,
                MissionDetails = launch.Details,
                InfoUrl        = launch.Links.Wikipedia,
                ChangedTime    = DateTime.UtcNow,
                UpdatedTime    = DateTime.UtcNow,
                Country        = country,
                Agency         = agency
            };

            return(launchDto);
        }
 public async Task <IActionResult?> Update([FromBody] LaunchDto dto)
 {
     return(await SaveRocket(dto));
 }
        public async Task AddLaunchToDb(LaunchDto launch)
        {
            await _context.AddAsync(launch);

            await SaveChangesAsync();
        }