示例#1
0
        public JsonResult DoesThisVendorExist()
        {
            VendorViewModel ViewModle   = new VendorViewModel();
            var             vendorCount = 0;

            try
            {
                var resolveRequest = HttpContext.Request;
                resolveRequest.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                string jsonString = new System.IO.StreamReader(resolveRequest.InputStream).ReadToEnd();
                //deserialse
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string vendorName = serializer.Deserialize <string>(jsonString);
                using (VendorViewModel presentaion = new VendorViewModel())
                {
                    vendorCount = presentaion.GetData()
                                  .Where(x => x.VendorName.ToUpper().Equals(vendorName.ToUpper())).Count();
                    return(new JsonResult
                    {
                        Data = new { Data = vendorCount, Success = true, ErrorMessage = "" },
                        ContentEncoding = System.Text.Encoding.UTF8,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult
                {
                    Data = new { Data = vendorCount, Success = false, ErrorMessage = ex.Message },
                    ContentEncoding = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
示例#2
0
        public JsonResult GetAllVendors()
        {
            /*
             * This is the method used to get all vendors for  rebinding
             * */


            var col = new List <VendorViewModel>();

            using (VendorViewModel vm = new VendorViewModel())
            {
                col = (from p in vm.GetData()

                       select p
                       ).ToList();

                var retVal = col.Select(c => new { label = c.VendorName, value = c.VendorID });
                return(Json(retVal, JsonRequestBehavior.AllowGet));
            }
        }