public void filterRecord(int length, string property, string value, string value2, ref UserMenu[] userMenu)
 {
     /* Fields that can be filter
      * Name
      * Desription
      * Status
      */
     //Filter for a specific patient
     int fetch;
     userMenu = null;
     if (property.Equals("Name"))
     {
         value = value.ToLower();
         var records = db.UserMenus.Where(um => um.DentalMenu.Name.ToLower().Contains(value) || um.DentalMenu.Name.ToLower().ToLower().Equals(value)).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getUserMenu = db.UserMenus.Where(um => um.DentalMenu.Name.ToLower().Contains(value) || um.DentalMenu.Name.ToLower().ToLower().Equals(value))
                 .OrderBy(um => um.Id).Skip((length)).Take(fetch).ToArray();
             userMenu = getUserMenu;
         }
     }
     else if (property.Equals("Description"))
     {
         value = value.ToLower();
         var records = db.UserMenus.Where(um => um.DentalMenu.Description.ToLower().Contains(value) || um.DentalMenu.Description.ToLower().ToLower().Equals(value)).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getUserMenu = db.UserMenus.Where(um => um.DentalMenu.Name.ToLower().Contains(value) || um.DentalMenu.Name.ToLower().ToLower().Equals(value))
                 .OrderBy(um => um.Id).Skip((length)).Take(fetch).ToArray();
             userMenu = getUserMenu;
         }
     }
     //status
     else
     {
         StringManipulation strManipulate = new StringManipulation(value, value2, "Integer");
         var records = db.UserMenus.Where(cs => cs.Status == strManipulate.intValue).Count();
         if (records > length)
         {
             if ((records - length) > pageSize)
                 fetch = pageSize;
             else
                 fetch = records - length;
             var getUserMenu = db.UserMenus.Where(um => um.Status == strManipulate.intValue)
                 .OrderBy(um => um.Id).Skip((length)).Take(fetch).ToArray();
             userMenu = getUserMenu;
         }
     }
 }
        public IHttpActionResult PostUserMenu(UserMenu userMenu)
        {
            response.status = "FAILURE";
            if (!ModelState.IsValid)
            {
                response.message = "Bad request.";
                return Ok(response);
            }
            try
            {
                if (!validateMenu(userMenu.UserTypeId, userMenu.MenuId))
                    response.message = "User already have this menu, please choose another menu.";
                else
                {
                    db.UserMenus.Add(userMenu);
                    db.SaveChanges();
                    response.status = "SUCCESS";
                    response.objParam1 = userMenu;
                }
            }
            catch(Exception e){
                response.message = e.InnerException.InnerException.Message.ToString();
            }

            return Ok(response);
        }
        public IHttpActionResult PutUserMenu(int id, UserMenu userMenu)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != userMenu.Id)
            {
                return BadRequest();
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserMenuExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 //Filtering
 public IHttpActionResult GetUserMenu(int length, string property, string value, string value2)
 {
     UserMenu[] userMenu = new UserMenu[pageSize];
     this.filterRecord(length, property, value, value2, ref userMenu);
     if (userMenu != null)
         return Ok(userMenu);
     else
         return Ok();
 }