public HttpResponseMessage Getstores(int id)
        {
            clsStores objStores = new clsStores();

            try
            {
                objStores = (from a in db.stores
                             where (a.id == id)
                             select new clsStores()
                {
                    id = a.id,
                    name = a.name,
                    address = a.address
                }).FirstOrDefault <clsStores>();


                if (objStores == null)
                {
                    objError = objResponse.responseError(HttpStatusCode.NotFound);
                    return(Request.CreateResponse(HttpStatusCode.NotFound, objError, Configuration.Formatters.JsonFormatter));
                }

                objResponseStores = objResponse.responseStoresSuccess(objStores, storesTotal());
                return(Request.CreateResponse(HttpStatusCode.OK, objResponseStores, Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                objError = objResponse.responseError(HttpStatusCode.BadRequest);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objError, Configuration.Formatters.JsonFormatter));
            }
        }
Esempio n. 2
0
        public async Task <List <clsStores> > getFillStore()
        {
            List <clsStores> lsStores = new List <clsStores>();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage ResStores = await client.GetAsync("services/stores/");

                    if (ResStores.IsSuccessStatusCode)
                    {
                        var            StoresResponse = ResStores.Content.ReadAsStringAsync().Result;
                        ResponseStores account        = JsonConvert.DeserializeObject <ResponseStores>(StoresResponse);
                        lsStores = JsonConvert.DeserializeObject <List <clsStores> >(account.stores.ToString());
                    }

                    ViewBag.StoreList = lsStores;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lsStores);
        }
        // GET: service/stores
        public HttpResponseMessage Getstores()
        {
            List <clsStores> lsStores = new List <clsStores>();

            lsStores = (from a in db.stores
                        select new clsStores()
            {
                id = a.id,
                name = a.name,
                address = a.address
            }).ToList <clsStores>();

            objResponseStores = objResponse.responseStoresSuccess(lsStores, storesTotal());
            return(Request.CreateResponse(HttpStatusCode.OK, objResponseStores));
        }
        public HttpResponseMessage GetStores()
        {
            try
            {
                var           stores   = _context.Stores.ToList();
                var           total    = stores.Count();
                List <Stores> lsStores = new List <Stores>();
                lsStores = stores;

                responseStores = response.responseStoresSuccess(lsStores, total);
                return(Request.CreateResponse(HttpStatusCode.OK, responseStores));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public HttpResponseMessage GetStores(int id)
        {
            try
            {
                var stores = _context.Stores.FindAsync(id);
                var total  = _context.Stores.Count();
                if (stores == null)
                {
                    reponseError = response.responseError(HttpStatusCode.NotFound);
                    return(Request.CreateResponse(HttpStatusCode.NotFound, reponseError, Configuration.Formatters.JsonFormatter));
                }

                responseStores = response.responseStoresSuccess(stores, total);
                return(Request.CreateResponse(HttpStatusCode.OK, responseStores, Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                reponseError = response.responseError(HttpStatusCode.BadRequest);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, reponseError, Configuration.Formatters.JsonFormatter));
            }
        }