Ejemplo n.º 1
0
        public async Task <List <QuoteSendDTO> > GetAllQuotePendingAsync()
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(apiUrl + "/quote-management/quotes/pending");

                string resp = await ResponseUtility.Verification(response);

                List <QuoteDTO>     quotes     = JsonConvert.DeserializeObject <List <QuoteDTO> >(resp);
                List <QuoteSendDTO> quotesSend = new List <QuoteSendDTO>();
                for (int i = 0; i < quotes.Count; i++)
                {
                    quotesSend.Add(TransformItemListAsync(quotes[i]).Result);
                }
                return(quotesSend);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Quote api not found", 408);
            }
        }
Ejemplo n.º 2
0
        public async void DeleteAsync(string id)
        {
            try {
                HttpResponseMessage response = await this.client.DeleteAsync(apiUrl + "/product-management/products/" + id);

                string result = await ResponseUtility.Verification(response);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Product api not found", 408);
            }
        }
Ejemplo n.º 3
0
        public async Task <List <ClientDTO> > GetAllClientAsync()
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(apiUrl + "/client-management/clients");

                string resp = await ResponseUtility.Verification(response);

                List <ClientDTO> clients = JsonConvert.DeserializeObject <List <ClientDTO> >(resp);
                return(clients);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Client api not found", 408);
            }
        }
Ejemplo n.º 4
0
        public async Task <QuoteSendDTO> GetQuoteAsync(String id)
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(apiUrl + "/quote-management/quotes/" + id);

                string resp = await ResponseUtility.Verification(response);

                QuoteDTO quoteDTO = JsonConvert.DeserializeObject <QuoteDTO>(resp);
                return(TransformItemListAsync(quoteDTO).Result);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Quote api not found", 408);
            }
        }
Ejemplo n.º 5
0
        public async Task <List <ProductGetDTO> > GetSomeProductsAsync(string codes)
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(apiUrl + "/product-management/products?ids=" + codes);

                string resp = await ResponseUtility.Verification(response);

                List <ProductGetDTO> products = JsonConvert.DeserializeObject <List <ProductGetDTO> >(resp);
                return(products);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Product api not found", 408);
            }
        }
Ejemplo n.º 6
0
        public async Task <ProductGetDTO> GetProductAsync(String id)
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(apiUrl + "/product-management/products/" + id);

                string resp = await ResponseUtility.Verification(response);

                ProductGetDTO productDTO = JsonConvert.DeserializeObject <ProductGetDTO>(resp);
                return(productDTO);
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Product api not found", 408);
            }
        }
Ejemplo n.º 7
0
        public async Task <ClientDTO> UpdateAsync(ClientUpdateDTO client, String id)
        {
            try {
                String json = JsonConvert.SerializeObject(client, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
                StringContent       data     = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await this.client.PutAsync(apiUrl + "/client-management/clients/" + id, data);

                string result = await ResponseUtility.Verification(response);

                return(JsonConvert.DeserializeObject <ClientDTO>(result));
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Client api not found", 408);
            }
        }
Ejemplo n.º 8
0
        private async Task <QuoteSendDTO> TransformItemListAsync(QuoteDTO quoteDTO)
        {
            QuoteSendDTO quoteSendDTO = new QuoteSendDTO();

            quoteSendDTO.Sold      = quoteDTO.Sold;
            quoteSendDTO.Date      = quoteDTO.Date;
            quoteSendDTO.QuoteName = quoteDTO.QuoteName;
            HttpResponseMessage clientResponse = await client.GetAsync(_configuration.GetSection("MicroServices").GetSection("Clients").Value + "/client-management/clients/" + quoteDTO.ClientCode);

            string clientResult = await ResponseUtility.Verification(clientResponse);

            ClientDTO clientDTO = JsonConvert.DeserializeObject <ClientDTO>(clientResult);

            quoteSendDTO.Client         = clientDTO;
            quoteSendDTO.QuoteListItems = new List <ListItemSendDTO>();
            if (quoteDTO.QuoteLineItems.Count > 0)
            {
                string codes = quoteDTO.QuoteLineItems[0].ProductCode;
                for (int i = 1; i < quoteDTO.QuoteLineItems.Count; i++)
                {
                    codes = codes + "," + quoteDTO.QuoteLineItems[i].ProductCode;
                }
                HttpResponseMessage productResponse = await client.GetAsync(_configuration.GetSection("MicroServices").GetSection("Products").Value + "/product-management/products?ids=" + codes);

                string productResult = await ResponseUtility.Verification(productResponse);

                List <ProductGetDTO> productos = JsonConvert.DeserializeObject <List <ProductGetDTO> >(productResult);
                for (int i = 0; i < quoteDTO.QuoteLineItems.Count; i++)
                {
                    ListItemSendDTO item = new ListItemSendDTO();
                    item.Price     = quoteDTO.QuoteLineItems[i].Price;
                    item.Quantity  = quoteDTO.QuoteLineItems[i].Quantity;
                    item.QuoteName = quoteDTO.QuoteLineItems[i].QuoteName;
                    item.Product   = productos.Find(x => x.Code.Equals(quoteDTO.QuoteLineItems[i].ProductCode));
                    quoteSendDTO.QuoteListItems.Add(item);
                }
            }
            return(quoteSendDTO);
        }
Ejemplo n.º 9
0
        public async Task <QuoteDTO> CreateQuote(QuoteDTO quote)
        {
            try {
                String json = JsonConvert.SerializeObject(quote, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
                StringContent       data     = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await this.client.PostAsync(apiUrl + "/quote-management/quotes", data);

                string result = await ResponseUtility.Verification(response);

                return(JsonConvert.DeserializeObject <QuoteDTO>(result));
            }
            catch (ServicesException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw new ServicesException("Quote api not found", 408);
            }
        }