Beispiel #1
0
        public ActionResult Search(SearchUserGroupParametersVM model)
        {
            try
            {
                object sortColumn    = "";
                object sortDirection = "";

                if (model.order.Count == 0)
                {
                    sortColumn    = "CreatedOn";
                    sortDirection = "desc";
                }
                else
                {
                    sortColumn    = model.columns[Convert.ToInt32(model.order[0].column)].data ?? (object)DBNull.Value;
                    sortDirection = model.order[0].dir ?? (object)DBNull.Value;
                }

                model.PageSize = Constants.PAGESIZE;
                var userGroups = userGroupRepository.SearchUserGroup(model, Convert.ToString(sortColumn), Convert.ToString(sortDirection));

                int totalRecords = 0;
                var dbRecords    = userGroups.Select(m => m.TotalCount).FirstOrDefault();

                if (dbRecords != 0)
                {
                    totalRecords = Convert.ToInt32(dbRecords);
                }

                return(Json(new
                {
                    IsSuccess = true,
                    CurrentPage = model.PageNum,
                    PageSize = Constants.PAGESIZE,
                    TotalRecords = totalRecords,
                    data = userGroups
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Search");
                return(Json(new { IsSuccess = false, errorMessage = e.Message }));
            }
        }