public Pager<UserInfoAccount> Query(UserInfoQueryParameter para) { var dataList = new Lazy<Pager<UserInfoAccount>>(); var sqlText = new StringBuilder(); //var pageSqlText = new StringBuilder(); sqlText.Append(@"SELECT U.ID ,UM.ACCOUNT as DefaultAccount ,U.PASSWORD ,U.NICKNAME ,U.GENDER ,U.COMPANYNAME ,U.ADDRESS ,U.REMARK FROM USERINFO AS U INNER JOIN USERINFOACCOUNT AS UM ON U.ID = UM.USERINFOID WHERE 1 = 1 "); var conditions = para.GenerateByOperate(GenerateOperate.Condition); //string.Empty.GenerateCondition(para); sqlText.Append(conditions); sqlText.Append(" ORDER BY Id DESC OFFSET "); sqlText.Append(((para.Skip) * para.Take).ToString()); sqlText.Append(" ROWS FETCH NEXT "); sqlText.Append(para.Take.ToString()); sqlText.Append(" ROWS ONLY;"); if (para.IsPage) { sqlText.Append(" SELECT COUNT(1) AS Total ,CEILING((COUNT(1)+0.0)/") .Append(para.Take.ToString()) .Append(") AS Pages FROM USERINFO WHERE 1 =1 ") .Append(conditions + ";"); //sqlText.Append(pageSqlText); } using (var conn = SqlServerDB.GetSqlConnection()) { using (var grid = conn.QueryMultiple(sqlText.ToString(), para)) { //dataList.Value.Items = data.ToArray(); dataList.Value.Items = grid.Read<UserInfoAccount>().ToArray(); if (para.IsPage) { var pageInfo = grid.Read().FirstOrDefault(); if (pageInfo == null) return dataList.Value; dataList.Value.Total = (int)pageInfo.Total; dataList.Value.Pages = (int)pageInfo.Pages; } else { return dataList.Value; } } } return dataList.Value; }
public ReturnResponse<UserInfoViewModels> Login(UserInfoViewModels userInfo) { var response = new ReturnResponse<UserInfoViewModels>(); var para = new UserInfoQueryParameter() { Account = userInfo.Account, //Password = userInfo.Password.Md5Compute32(), AccountType = userInfo.Account.GetAccountType(), Take = 1, IsPage = false }; var res = Query(para); if (res.IsSuccess && res.Body.Items.Any()) { response.Body = res.Body.Items.FirstOrDefault(); if (response.Body != null && response.Body.DataStatus == 1) { response.ResponseCode = 403; response.Message = "user has been forbidden"; } else if (response.Body != null && !userInfo.Password.Md5Compute32().Equals(response.Body.Password)) { response.ResponseCode = 400; response.Message = "user name or password error"; } else { response.ResponseCode = 1; response.Message = "login success"; } } else { response.ResponseCode = 400; response.Message = "user name doesn't exist"; } return response; }
public ReturnResponse<Pager<UserInfoViewModels>> Query(UserInfoQueryParameter parameter) { var userInfoAccount = _userInfoAccountDal.Query(parameter); var list = new List<UserInfoViewModels>(); var pagers = new Pager<UserInfoViewModels>(); if (userInfoAccount.Items.Any()) { userInfoAccount.Items.Each(account => { var userInfoRes = _userInfoDal.Query(new UserInfoQueryParameter() { ID = account.UserInfoID }); var userInfo = userInfoRes.Items.FirstOrDefault(); if (userInfo != null) list.Add(new UserInfoViewModels() { Account = account.Account, AccountType = account.Account.GetAccountType(), Password = userInfo.Password, CompanyName = userInfo.CompanyName, Address = userInfo.Address, Gender = userInfo.Gender, NickName = userInfo.NickName, Id = userInfo.Id }); }); pagers.Total = userInfoAccount.Total; pagers.Pages = userInfoAccount.Pages; pagers.Items = list.ToArray(); return new ReturnResponse<Pager<UserInfoViewModels>> { Body = pagers, ResponseCode = 1, Message = "Success" }; } return new ReturnResponse<Pager<UserInfoViewModels>> { Body = pagers, ResponseCode = 400, Message = "Not exist" }; }