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

            return Ok(response);
        }
        public IHttpActionResult PutUserType(int id, UserType userType)
        {
            response.status = "SUCCESS";
            if (!ModelState.IsValid || id != userType.Id)
            {
                response.message = "Bad request.";
                return Ok(response);
            }

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

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

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