public IList <ServiceUserVoleInfo> GetList() { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,UserId,ServiceItemId,LastUpdatedDate from Service_UserVole order by LastUpdatedDate desc " ); IList <ServiceUserVoleInfo> list = new List <ServiceUserVoleInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString())) { if (reader != null && reader.HasRows) { while (reader.Read()) { ServiceUserVoleInfo model = new ServiceUserVoleInfo(); model.Id = reader.GetGuid(0); model.UserId = reader.GetGuid(1); model.ServiceItemId = reader.GetGuid(2); model.LastUpdatedDate = reader.GetDateTime(3); list.Add(model); } } } return(list); }
public ServiceUserVoleInfo GetModel(object Id) { ServiceUserVoleInfo model = null; string cmdText = @"select top 1 Id,UserId,ServiceItemId,LastUpdatedDate from Service_UserVole where Id = @Id " ; SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(Id.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new ServiceUserVoleInfo(); model.Id = reader.GetGuid(0); model.UserId = reader.GetGuid(1); model.ServiceItemId = reader.GetGuid(2); model.LastUpdatedDate = reader.GetDateTime(3); } } } return(model); }
public IList <ServiceUserVoleInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,UserId,ServiceItemId,LastUpdatedDate from Service_UserVole "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } IList <ServiceUserVoleInfo> list = new List <ServiceUserVoleInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { ServiceUserVoleInfo model = new ServiceUserVoleInfo(); model.Id = reader.GetGuid(0); model.UserId = reader.GetGuid(1); model.ServiceItemId = reader.GetGuid(2); model.LastUpdatedDate = reader.GetDateTime(3); list.Add(model); } } } return(list); }
public string SaveServiceUserVole(string username, Guid serviceItemId) { try { if (serviceItemId.Equals(Guid.Empty)) { return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", false, "服务ID【" + serviceItemId + "】无效,请检查")); } MembershipUser user = Membership.GetUser(username); if (user == null) { return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", false, "用户【" + username + "】不存在或已被删除")); } object userId = user.ProviderUserKey; ServiceUserVole bll = new ServiceUserVole(); ServiceUserVoleInfo model = new ServiceUserVoleInfo(); model.UserId = Guid.Parse(userId.ToString()); model.ServiceItemId = serviceItemId; model.LastUpdatedDate = DateTime.Now; int effect = 0; using (TransactionScope scope = new TransactionScope()) { if (bll.IsExist(userId, serviceItemId)) { effect = 110; } else { effect = bll.Insert(model); } scope.Complete(); } if (effect == 110) { return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", false, "您已投票,请不要重复投票!")); } if (effect > 0) { return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", true, "投票成功")); } else { return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", false, "投票失败,请正确操作,必要时请联系管理员")); } } catch (Exception ex) { new CustomException(string.Format("服务-接口:string SaveServiceUserVole,异常:{0}", ex.Message), ex); return(string.Format("<Rsp><IsOK>{0}</IsOK><RtMsg>{1}</RtMsg></Rsp>", false, "系统异常,原因:" + ex.Message + "")); } }
public IList <ServiceUserVoleInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select count(*) from Service_UserVole "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms); if (totalRecords == 0) { return(new List <ServiceUserVoleInfo>()); } sb.Clear(); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, Id,UserId,ServiceItemId,LastUpdatedDate from Service_UserVole " ); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <ServiceUserVoleInfo> list = new List <ServiceUserVoleInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { ServiceUserVoleInfo model = new ServiceUserVoleInfo(); model.Id = reader.GetGuid(1); model.UserId = reader.GetGuid(2); model.ServiceItemId = reader.GetGuid(3); model.LastUpdatedDate = reader.GetDateTime(4); list.Add(model); } } } return(list); }
public int Insert(ServiceUserVoleInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"insert into Service_UserVole (UserId,ServiceItemId,LastUpdatedDate) values (@UserId,@ServiceItemId,@LastUpdatedDate) " ); SqlParameter[] parms = { new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@ServiceItemId", SqlDbType.UniqueIdentifier), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.UserId; parms[1].Value = model.ServiceItemId; parms[2].Value = model.LastUpdatedDate; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), parms)); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(ServiceUserVoleInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(ServiceUserVoleInfo model) { return(dal.Insert(model)); }