/// 获取参数 /// </summary> /// <param name="useropeninfo"></param> /// <returns></returns> public Dictionary <string, string> GetParameters(UserOpenInfo useropeninfo) { Dictionary <string, string> dict = new Dictionary <string, string>(); if (useropeninfo.id != null) { dict.Add("@id", useropeninfo.id.ToString()); } if (useropeninfo.userId != null) { dict.Add("@userId", useropeninfo.userId.ToString()); } if (useropeninfo.lat != null) { dict.Add("@lat", useropeninfo.lat.ToString()); } if (useropeninfo.lng != null) { dict.Add("@lng", useropeninfo.lng.ToString()); } if (useropeninfo.openTime != null) { dict.Add("@openTime", useropeninfo.openTime.ToString()); } if (useropeninfo.closeTime != null) { dict.Add("@closeTime", useropeninfo.closeTime.ToString()); } if (useropeninfo.address != null) { dict.Add("@address", useropeninfo.address.ToString()); } return(dict); }
/// <summary> /// add /// </summary> /// <param name="UserOpenInfo"></param> /// <returns></returns> public int Add(UserOpenInfo model) { var str = GetInsertStr(model) + " select @@identity"; var dict = GetParameters(model); return(Convert.ToInt32(SqlHelperHere.ExecuteScalar(str, dict))); }
} /// <summary> /// 更新 /// </summary> /// <param name="useropeninfo"></param> /// <returns>是否成功</returns> public string GetUpdateStr(UserOpenInfo useropeninfo) { StringBuilder part1 = new StringBuilder(); part1.Append("update useropeninfo set "); if (useropeninfo.userId != null) { part1.Append("userId = @userId,"); } if (useropeninfo.lat != null) { part1.Append("lat = @lat,"); } if (useropeninfo.lng != null) { part1.Append("lng = @lng,"); } if (useropeninfo.openTime != null) { part1.Append("openTime = @openTime,"); } if (useropeninfo.closeTime != null) { part1.Append("closeTime = @closeTime,"); } if (useropeninfo.address != null) { part1.Append("address = @address,"); } int n = part1.ToString().LastIndexOf(","); part1.Remove(n, 1); part1.Append(" where id= @id "); return(part1.ToString()); }
/// <summary> /// update /// </summary> /// <param name="UserOpenInfo"></param> /// <returns></returns> public void Update(UserOpenInfo model) { //CacheHelper.LockCache("UserOpenInfo"); var str = GetUpdateStr(model); var dict = GetParameters(model); SqlHelperHere.ExcuteNon(str, dict); //CacheHelper.ReleaseLock("UserOpenInfo"); }
public HttpResponseMessage UploadUserLocation(UserReq req) { var userId = Convert.ToInt32(req.userId); var lat = req.lat; var lng = req.lng; var address = req.address; var now = DateTime.Now; if (userId != 0) { UserOpenInfo uo = new UserOpenInfo(); uo.lat = lat; uo.lng = lng; uo.openTime = now; uo.address = address; uo.userId = userId; UserOpenInfoOper.Instance.Add(uo); return(ControllerHelper.Instance.JsonResult(200, "已记录")); } return(ControllerHelper.Instance.JsonResult(200, "没登陆不记录")); }
/// <summary> /// 插入 /// </summary> /// <param name="useropeninfo"></param> /// <returns>是否成功</returns> public string GetInsertStr(UserOpenInfo useropeninfo) { StringBuilder part1 = new StringBuilder(); StringBuilder part2 = new StringBuilder(); if (useropeninfo.userId != null) { part1.Append("userId,"); part2.Append("@userId,"); } if (useropeninfo.lat != null) { part1.Append("lat,"); part2.Append("@lat,"); } if (useropeninfo.lng != null) { part1.Append("lng,"); part2.Append("@lng,"); } if (useropeninfo.openTime != null) { part1.Append("openTime,"); part2.Append("@openTime,"); } if (useropeninfo.closeTime != null) { part1.Append("closeTime,"); part2.Append("@closeTime,"); } if (useropeninfo.address != null) { part1.Append("address,"); part2.Append("@address,"); } StringBuilder sql = new StringBuilder(); sql.Append("insert into useropeninfo(").Append(part1.ToString().Remove(part1.Length - 1)).Append(") values (").Append(part2.ToString().Remove(part2.Length - 1)).Append(")"); return(sql.ToString()); } /// <summary>