Esempio n. 1
0
        // GET: Admin/GetJSONVehicleModels/Id
        public string GetJSONVehicleModels(int id)
        {
            //Retrieve model names and populate the VehicleModelsList model
            var model = VehicleModelBLL.GetJSONModelByManufacturer(id);

            //Send JSON response to calling object
            return(JsonConvert.SerializeObject(model));
        }
Esempio n. 2
0
        public string UpdateModel()
        {
            var ReturnValue = 0;

            /*var divisor = 0;
             * //Cause a deliberate error to test the AJAX/JSON responses
             * var result = 10 / divisor;
             */
            String postedData     = new System.IO.StreamReader(System.Web.HttpContext.Current.Request.InputStream).ReadToEnd();
            var    myPostedData   = JsonConvert.SerializeObject(postedData);
            var    data           = JObject.Parse(postedData);
            var    ManufacturerID = (int)data["ManufacturerID"];
            var    ModelID        = (int)data["ModelID"];
            var    ModelName      = data["ModelName"].ToString();
            var    FullName       = Request.Cookies["userInfo"]["FullName"];

            if (ModelID < 1)
            {
                //This is a new model being added
                VehicleModelBLL.AddNewModel(ManufacturerID, ModelName, FullName, out int returnValue);
                ReturnValue = returnValue;
                if (ReturnValue == -1)
                {
                    return(JsonConvert.SerializeObject("-1"));
                }
            }
            else
            {
                //This is an update
                VehicleModelBLL.UpdateModel(ModelID, ModelName, FullName, out int returnValue);
                ReturnValue = returnValue;
                if (ReturnValue == -1)
                {
                    return(JsonConvert.SerializeObject("-1"));
                }
            }

            //Retrieve the updated model names and populate the VehicleModelsList model
            var model = VehicleModelBLL.GetJSONModelByManufacturer(ManufacturerID);

            //Send JSON response to calling object
            return(JsonConvert.SerializeObject(model));
        }