public void filterRecord(int length, string property, string value, string value2, ref TreatmentType[] treatmentType)
 {
     /* Fields that can be filter
      * Name
      * Desription
      * Status
      */
     //Filter for a specific patient
     int fetch;
     treatmentType = null;
     if (property.Equals("Name"))
     {
         value = value.ToLower();
         var records = db.TreatmentTypes.Where(cs => cs.Name.ToLower().Contains(value) || cs.Name.ToLower().ToLower().Equals(value)).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getTreatmentType = db.TreatmentTypes.Where(cs => cs.Name.ToLower().Contains(value) || cs.Name.ToLower().ToLower().Equals(value))
                 .OrderBy(cs => cs.Id).Skip((length)).Take(fetch).ToArray();
             treatmentType = getTreatmentType;
         }
     }
     else if (property.Equals("Description"))
     {
         value = value.ToLower();
         var records = db.TreatmentTypes.Where(cs => cs.Description.ToLower().Contains(value) || cs.Description.ToLower().ToLower().Equals(value)).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getTreatmentType = db.TreatmentTypes.Where(cs => cs.Description.ToLower().Contains(value) || cs.Description.ToLower().ToLower().Equals(value))
                 .OrderBy(cs => cs.Id).Skip((length)).Take(fetch).ToArray();
             treatmentType = getTreatmentType;
         }
     }
     //status
     else
     {
         StringManipulation strManipulate = new StringManipulation(value, value2, "Integer");
         var records = db.TreatmentTypes.Where(cs => cs.Status == strManipulate.intValue).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getTreatmentType = db.TreatmentTypes.Where(cs => cs.Status == strManipulate.intValue)
                 .OrderBy(cs => cs.Id).Skip((length)).Take(fetch).ToArray();
             treatmentType = getTreatmentType;
         }
     }
 }
        public IHttpActionResult PostTreatmentType(TreatmentType treatmentType)
        {
            response.status = "FAILURE";
            if (!ModelState.IsValid)
            {
                response.message = "Bad request.";
                return Ok(response);
            }
            try
            {
                db.TreatmentTypes.Add(treatmentType);
                db.SaveChanges();
                response.status = "SUCCESS";
                response.objParam1 = treatmentType;
            }
            catch (Exception e) {
                response.message = e.InnerException.InnerException.Message.ToString();
            }

            return Ok(response);
        }
        public IHttpActionResult PutTreatmentType(int id, TreatmentType treatmentType)
        {
            response.status = "FAILURE";
            if (!ModelState.IsValid || id != treatmentType.Id)
            {
                response.message = "Bad request.";
                return Ok(response);
            }

            db.Entry(treatmentType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                response.status = "SUCCESS";
                response.objParam1 = treatmentType;
            }
            catch (Exception e)
            {
                if (!TreatmentTypeExists(id))
                {
                    response.message = "Treatment type doesn't exist.";
                }
                else
                {
                    response.message = e.InnerException.InnerException.Message.ToString();
                }
            }

            return Ok(response);
        }
 //Filtering
 public IHttpActionResult GetTreatmentType(int length, int status, string property, string value, string value2)
 {
     TreatmentType[] treatmentType = new TreatmentType[pageSize];
     this.filterRecord(length, status, property, value, value2, ref treatmentType);
     if (treatmentType != null)
         return Ok(treatmentType);
     else
         return Ok();
 }