public string EditProduct() { using (ProductsContext _prodContext = new ProductsContext()) { int id = Convert.ToInt32(Request.Params["ProductId"]); string name = Request.Params["Name"]; float price = Convert.ToSingle(Request.Params["Price"]); Product prod = _prodContext.Products.Where(i => i.Id == id).First(); prod.Name = name; prod.Price = price; _prodContext.SaveChanges(); ProductPager list = new ProductPager(_prodContext); List <Product> products = list.GetPage(10); List <Object> anonValueList = new List <Object>(); foreach (var j in products) { anonValueList.Add(new { Id = j.Id, Name = j.Name, Price = j.Price, Count = j.Count }); } string jsonResult = JsonConvert.SerializeObject(anonValueList.ToArray()); return(jsonResult); } }
public string GetProducts() { using (ProductsContext _prodContext = new ProductsContext()) { ProductPager list = new ProductPager(_prodContext); int rowCount = 10; int firstIndex = (Convert.ToInt32(Request.Params["page"]) - 1) * rowCount; List <Product> products = list.GetPage(firstIndex, rowCount); List <Object> anonValueList = new List <Object>(); foreach (var j in products) { anonValueList.Add(new { Id = j.Id, Name = j.Name, Price = j.Price, Count = j.Count }); } string jsonResult = JsonConvert.SerializeObject(anonValueList.ToArray()); return(jsonResult); } }