Get disease ICD code in C# using ICD10 API

public string GetICDCode(string ICDCode)
        {
            DiagnosisModel model = new DiagnosisModel();
            String postURL = string.Format("http://icd10api.com/?code={0}&desc=short&r=json", ICDCode);
            WebRequest request = WebRequest.Create(postURL);
            request.Method = "GET";
            request.ContentType = "application/json; charset=utf-8";

            var response = (HttpWebResponse)request.GetResponse();
            string jsonText;
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                jsonText = sr.ReadToEnd();
            }
            return jsonText;

        }

We created a method for getting icd code.

Create Model for icd code vlaues and data

public class ICDCode
        {
            public string Name { get; set; }
            public string[] Inclusions { get; set; }
            public string[] ExcludesOne { get; set; }
            public string[] ExcludesTwo { get; set; }
            public string Description { get; set; }
            public string Valid { get; set; }
            public string Type { get; set; }
            public string Response { get; set; }
        }

Just pass icd code in above method and it will give you result as json,

deserilize it with you model class and store in your model properties.

ICDCode model = new ICDCode();

var jsonResultICDCode = GetICDCode(yourICDcode);

model.ICDResponse = new JavaScriptSerializer().Deserialize<ICDCode>(jsonResultICDCode);

If your ICD code is valid than, it will return
model.ICDResponse.Valid=1 and model.ICDResponse.Response == “True”

Now you can get all information about icd code in your model properties.

Enum dropdown bind in asp.net MVC razor

How do you create dropdown list from enum in asp.net MVC

  1. Write Enum
public enum MeetingType
        {
            [Description("First")]
            FIRST= 1,
            [Description("Second")]
            SECOND= 2,
            [Description("Third")]
            THIRD= 3
        }

public string Name{get;set;}

After Enum we will write get select list code from enum in controller section in those controller that will have the view of dropdown.

public ActionResult GetDropdown()
{
var enumData = from Demo e in Enum.GetValues(typeof(Demo))
                           select new
                           {
                               Value= (int)e,
                               Text= e
                           };
            ViewBag.EnumList = new SelectList(enumData,"Value","Text");
return View();
}

Here Demo is the Enum name and we created a list type of selectlist for dropdown.

Now we can use this ViewBag.EnumList in our dropdown list.

Razor Code:

@Html.DropDownList("Name", ViewBag.EnumList as SelectList, "Select Type", new { @class = "form-control" })

If you use @Html.DropDownListFor() Then for strongly bind code is below:

@Html.DropDownListFor(x => x.Name, (IEnumerable<SelectListItem>)ViewBag.EnumList, "Select Type", new { @class = "form-control" })

And now you can bind your dropdown with your Name model attribute.

How to get System IP address in ASP.NET MVC C#?

Getting client machine ip address in asp.net mvc.

you have to use System.Web.HttpContext context = System.Web.HttpContext.Current;
for current request.

public static string GetIPAddress()
        {
            System.Web.HttpContext context = System.Web.HttpContext.Current;
            string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (!string.IsNullOrEmpty(ipAddress))
            {
                string[] addresses = ipAddress.Split(',');
                if (addresses.Length != 0)
                {
                    return addresses[0];
                }
            }

            return context.Request.ServerVariables["REMOTE_ADDR"];
        }