BIMToolkitAPIClient.Controllers.PropertyController.Property C# (CSharp) Method

Property() public method

public Property ( string searchTerm ) : System.Web.Mvc.ActionResult
searchTerm string
return System.Web.Mvc.ActionResult
        public ActionResult Property(string searchTerm)
        {
            if (String.IsNullOrWhiteSpace(searchTerm))
            {
                return RedirectToAction("Index", "Properties");
            }

            var model = new Properties();

            string propertyJson;
            int authEnvID;
            bool successfullyParsed = int.TryParse(searchTerm, out authEnvID);

            // search by ID
            if (successfullyParsed)
            {
                propertyJson = ApiAccess.CallApi(string.Format("properties/propertybyid/{0}", searchTerm));
                Property propertyById = JsonConvert.DeserializeObject<Property>(propertyJson);
                model.PropertiesList.Add(propertyById);

                ViewBag.Title = string.Format("{0} | {1}", propertyById.LongName, propertyById.ID);
            }
            // or by first few letters of name
            else
            {
                propertyJson = ApiAccess.CallApi(string.Format("properties/propertiesbyname/{0}", searchTerm));
                List<Property> propertiesByName = JsonConvert.DeserializeObject<List<Property>>(propertyJson);
                model.PropertiesList.AddRange(propertiesByName);

                ViewBag.Title = string.Format("{0} results beginning with '{1}'", propertiesByName.Count(), searchTerm.Trim());
            }

            model.Json = FormatJson(propertyJson);

            if (String.IsNullOrWhiteSpace(model.Json) || model.Json == "null")
            {
                return RedirectToAction("Index", "Property");
            }

            return View(model);
        }