Exemplo n.º 1
0
        private async Task <IActionResult?> SaveRocket(RocketDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(CreateResponse(new BaseServiceResponse <RocketDto>(dto, System.Net.HttpStatusCode.BadRequest)));
            }

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

                transaction.Commit();

                return(CreateResponse(response));
            }
        }
Exemplo n.º 2
0
        public async Task <RocketDto?> SaveRocket(RocketDto dto)
        {
            try
            {
                Task <HttpResponseMessage>?saveTask;
                var content = _serviceResponseHandler.BuildJsonContent(dto);
                if (dto.RocketId == 0)
                {
                    saveTask = _httpClient.PostAsync("api/Rockets", content);
                }
                else
                {
                    saveTask = _httpClient.PutAsync("api/Rockets", content);
                }

                var response = await saveTask;
                return(await _serviceResponseHandler.HandleJsonResponse <RocketDto>(response));
            }
            catch (AccessTokenNotAvailableException exception)
            {
                exception.Redirect();
            }
            return(null);
        }
Exemplo n.º 3
0
 public async Task <IActionResult?> Update([FromBody] RocketDto dto)
 {
     return(await SaveRocket(dto));
 }