Exemplo n.º 1
0
 public static bool CheckExistsPhoneNumber(string phoneNumber, int?currentUserId)
 {
     if (string.IsNullOrWhiteSpace(phoneNumber))
     {
         return(true);
     }
     try
     {
         string sWhere = string.Concat("LOWER(a.Tel) = LOWER('", phoneNumber.Trim(), "') ");
         if (currentUserId.HasValue && currentUserId.Value > 0)
         {
             sWhere += string.Concat(" AND a.SysUserId <> ", currentUserId.Value);
         }
         var sysUserAction = new SysUserAction();
         var existsList    = sysUserAction.List(sWhere, string.Empty, 0, 1);
         return(existsList != null && existsList.Count > 0);
     }
     catch (Exception exception)
     {
         Ultity.TFunction.WriteToLog(exception);
         return(true);
     }
 }
Exemplo n.º 2
0
        public ActionResult GetData(int?page, int?pageSize, string key, int?sort, string usedState)
        {
            try
            {
                var objRef           = new object[5];
                int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
                if (currentPageIndex < 0)
                {
                    currentPageIndex = 0;
                }
                pageSize = pageSize.HasValue ? pageSize : rowInPage;
                string sWhere = (AuthorizeUser.IsHost() || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll)) ? " 1=1 " : " a.CreatedBy =" + WebSecurity.CurrentUserId;
                if (!string.IsNullOrEmpty(key))
                {
                    key            = key.Trim();
                    ViewBag.Search = key;
                    sWhere        += " and ( a.FullName like N'%" + key + "%' or dbo.ConvertToNoSigned(a.FullName) like  dbo.ConvertToNoSigned(N'%" + key + "%') ";
                    sWhere        += " or  a.UserName like N'%" + key + "%' or dbo.ConvertToNoSigned(a.UserName) like  dbo.ConvertToNoSigned(N'%" + key + "%')) ";
                }

                if (!string.IsNullOrEmpty(usedState))
                {
                    if (!usedState.Equals(Ultity.Constant.All.ToString()))
                    {
                        ViewBag.UsedState = Ultity.TFunction.GetAllUsedStateSelected(CommonHelper.Convert.ConvertToInt32(usedState));
                        sWhere            = string.IsNullOrEmpty(sWhere) ? " a.UsedState=" + usedState + "" : (sWhere + " AND a.UsedState=" + usedState + " ");
                    }
                }
                string sSort = "a.CreatedDate DESC";
                if (sort.HasValue)
                {
                    switch (sort.Value)
                    {
                    case 0:
                        sSort            = "a.Name ASC";
                        ViewBag.SortName = "1";
                        break;

                    case 1:
                        sSort            = "a.Name DESC";
                        ViewBag.SortName = "2";
                        break;

                    case 2:
                        ViewBag.SortName = "0";
                        sSort            = "a.Orders ASC";
                        break;
                    }
                }
                else
                {
                    ViewBag.SortName = "0";
                }
                objRef[0] = sWhere;
                objRef[1] = sSort;
                objRef[2] = currentPageIndex;
                objRef[3] = pageSize;
                objRef[4] = 0;
                var modelList = _sysAction.List(ref objRef);
                int totalRow  = CommonHelper.Convert.ConvertToInt32(objRef[4]);

                //Check after deleted last item in page . Redirect page close have value smaller
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Success, Data = modelList, TotalPage = totalRow, CurrentPage = currentPageIndex, PageSize = pageSize }));
                }
            }
            catch (Exception exception)
            {
                Ultity.TFunction.WriteToLog(exception);
                return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
            }
            return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
        }