Exemplo n.º 1
0
        public int PostStore(StoreJSON objStore)
        {
            int storeid;

            storeid = _storeRepository.PostStore(objStore);
            return(storeid);
        }
        public int PostStore(StoreJSON objStore)
        {
            RootObject objlist = JsonConvert.DeserializeObject <RootObject>(Json);
            int?       storeid = objlist.stores.Max(prod => (int?)prod.id) + 1;

            if (storeid == null)
            {
                storeid = 1;
            }
            objStore.id = (int)storeid;
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var jsonFile             = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/productjson.json");
            var json             = File.ReadAllText(jsonFile);
            var jsonObj          = JObject.Parse(json);
            var experienceArrary = jsonObj.GetValue("stores") as JArray;
            var newproductarray  = jss.Serialize(objStore);
            var newproduct       = JObject.Parse(newproductarray);

            experienceArrary.Add(newproduct);

            jsonObj["stores"] = experienceArrary;
            string newJsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj,
                                                                               Newtonsoft.Json.Formatting.Indented);

            File.WriteAllText(jsonFile, newJsonResult);
            return((int)storeid);
        }
Exemplo n.º 3
0
        public StoreJSON GetStore(int id)
        {
            StoreJSON ObjStore;

            ObjStore = _storeRepository.GetStore(id);
            if (ObjStore == null)
            {
                ObjStore = new StoreJSON();
            }
            return(ObjStore);
        }
Exemplo n.º 4
0
        public HttpResponseMessage PostStore(StoreJSON objStore)
        {
            int newprodid = 0;

            if (ModelState.IsValid)
            {
                newprodid = _storeBl.PostStore(objStore);
            }
            HttpResponseMessage response;

            if (newprodid == 0)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.OK, "New Store is created");
            }
            return(response);
        }
Exemplo n.º 5
0
        public JsonResult <StoreJSON> GetStore(int id)
        {
            StoreJSON objStore = _storeBl.GetStore(id);

            return(Json(objStore));
        }