Exemple #1
0
        public HttpResponseMessage GetAukcijeAktivne(HttpRequestMessage request, [FromBody] KriterijPretrageModel kriterij)
        {
            HttpResponseMessage response = null;

            try
            {
                using (AukcijeClient proxy = new AukcijeClient())
                {
                    proxy.Open();
                    AukcijaDetailDTO[] aukcije = proxy.GetAllAktivne(kriterij.KategorijaId, kriterij.StringZaPretragu);
                    response = request.CreateResponse <AukcijaDetailDTO[]>(HttpStatusCode.OK, aukcije);
                    proxy.Close();
                }
            }
            catch (FaultException ex)
            {
                response = request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
            catch (Exception ex)
            {
                response = request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }
        public async Task <List <AukcijaDetailDTO> > GetAktivneAukcije(string pretraga = "")
        {
            KriterijPretrageModel kp = new KriterijPretrageModel {
                StringZaPretragu = pretraga
            };
            Uri uri = new Uri(ViewModelHelper.siteUrl + "/api/aukcija/allaktivne");

            var content = JsonConvert.SerializeObject(kp);

            try
            {
                using (HttpClient httpClient = ViewModelHelper.GetHttpClient(""))
                {
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);
                    request.Content = new HttpStringContent(content);
                    request.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = await httpClient.SendRequestAsync(request).AsTask();

                    if (response.StatusCode == HttpStatusCode.Ok)
                    {
                        List <AukcijaDetailDTO> aukcije = JsonConvert.DeserializeObject <List <AukcijaDetailDTO> >(response.Content.ToString());

                        return(aukcije);
                    }

                    return(null);
                }
            }
            catch (Exception)
            {
                throw new Exception("Greška prilikom konekcije na server.");
            }
        }
Exemple #3
0
        public HttpResponseMessage GetAll(HttpRequestMessage request, [FromBody] KriterijPretrageModel kriterij)
        {
            HttpResponseMessage response = null;

            try
            {
                using (AukcijeClient proxy = new AukcijeClient())
                {
                    proxy.Open();
                    AukcijaDetailDTO[] aukcije = proxy.GetAll(kriterij.Zavrsena);
                    if (kriterij.Page > 0)
                    {
                        RezultatModel rezultat = new RezultatModel
                        {
                            brojAukcija = aukcije.Count(),
                            aukcije     = aukcije.Page(kriterij.Page, kriterij.PageSize).ToArray()
                        };

                        response = request.CreateResponse <RezultatModel>(HttpStatusCode.OK, rezultat);
                    }
                    else
                    {
                        response = request.CreateResponse <AukcijaDetailDTO[]>(HttpStatusCode.OK, aukcije);
                    }
                    proxy.Close();
                }
            }
            catch (FaultException ex)
            {
                response = request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
            catch (Exception ex)
            {
                response = request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }