async public Task <EOResponse> Create(EconomicOperator economicOperator)
        {
            var uri = API.EconomicOperator.CreateEconomicOperator(_remoteServiceBaseUrl);
            var economicOperatorDto = EconomicOperatorViewModelToDto(economicOperator);
            var jsonInString        = JsonConvert.SerializeObject(economicOperatorDto);
            var response            = await _httpClient.PostAsync(uri, new StringContent(jsonInString, Encoding.UTF8, "application/json"));

            if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
            {
                throw new Exception("Error creando el economic operator");
            }
            var responseString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <EOResponse>(responseString);

            try
            {
                response.EnsureSuccessStatusCode();
                return(result);
            }
            catch
            {
                return(result);
            }
        }
Пример #2
0
        public async Task <IActionResult> GetEO(string eoid)
        {
            var model = new EOResult();

            try
            {
                model = await _economicOperatorService.GetEconomicOperatorByEOID(eoid);


                if (model == null)
                {
                    BadRequest(eoid);
                }

                var eo = new EconomicOperator
                {
                    Id          = model.Id,
                    ActiveFrom  = model.ActiveFrom,
                    Description = model.Description,
                    Address     = model.Address,
                    City        = model.City,
                    Country     = model.Country,
                    Name        = model.Name,
                    NewId       = model.NewId,
                    ZipCode     = model.ZipCode
                };
                return(Json(new { status = "OK", data = eo }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "ERROR", data = ex.Message }));
            }
        }
Пример #3
0
        public ActionResult EconomicOperator()
        {
            var model = new EconomicOperator();

            var countries = GetCountries();

            ViewBag.Countries = CountriesFillDropDown(countries.Items);

            var eoids = GetEOIDS();

            ViewBag.EOIDs = FillDropDown(eoids);

            return(View("EconomicOperators", model));
        }
Пример #4
0
        public async Task <ActionResult> EconomicOperator(EconomicOperator economicOperator)
        {
            if (economicOperator.NewId != null)
            {
                economicOperator.Id = economicOperator.NewId;

                if (ModelState.IsValid)
                {
                    try
                    {
                        var result = await _economicOperatorService.Create(economicOperator);

                        if (result != null && result.ResponseResult.Errors == null)
                        {
                            ViewBag.Status   = "EO con ID " + result.Reference.EONumber + " ha sido registrado";
                            economicOperator = new EconomicOperator();
                        }
                        else
                        {
                            ViewBag.Status   = result.ResponseResult.Errors.FirstOrDefault().ErrorMessage;
                            economicOperator = new EconomicOperator();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new RequestErrorException(ex.Message);
                    }
                }
            }

            ModelState.Clear();

            var countries = GetCountries();

            ViewBag.Countries = CountriesFillDropDown(countries.Items);

            var eoids = GetEOIDS();

            ViewBag.EOIDs = FillDropDown(eoids);

            return(View("EconomicOperators", economicOperator));
        }
        private EconomicOperatorDto EconomicOperatorViewModelToDto(EconomicOperator economicOperator)
        {
            RequestHeader requestHeader = new RequestHeader();

            requestHeader.DateRequest = DateTimeOffset.UtcNow.ToString("yyyyMMdd");
            requestHeader.TimeRequest = DateTimeOffset.UtcNow.ToString("hhmmss");
            requestHeader.RequestId   = Guid.NewGuid().ToString();

            return(new EconomicOperatorDto()
            {
                Id = economicOperator.Id,
                Name = economicOperator.Name,
                ActiveFrom = economicOperator.ActiveFrom,
                Address = economicOperator.Address,
                City = economicOperator.City,
                ZipCode = economicOperator.ZipCode,
                Country = economicOperator.Country,
                Description = economicOperator.Description,
                RequestHeader = requestHeader
            });
        }