/// <summary> /// 修改. /// </summary> /// <param name="entity">.</param> /// <returns>.</returns> public async Task <BaseResult <FoodEntity> > Update(FoodEntity entity) { StringBuilder sb = new StringBuilder(); string detailSql = @"SELECT * FROM dbo.tbFood WHERE id=@id"; var i = await Detail(entity.id, detailSql); if (i == null) { throw new Exception("数据不存在"); } sb.AppendFormat(@"UPDATE dbo.tbFood SET name = '{0}', material ='{1}', method = '{2}', act ='{3}',image='{4}' WHERE id={5} ", entity.name, entity.material, entity.method, entity.act, entity.image, entity.id); var result = new BaseResult <FoodEntity>(); try { await Update(entity, sb.ToString()); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 获取总记录数. /// </summary> /// <returns>返回记录总数.</returns> public async Task <BaseResult <AcupointEntity> > GetCount() { string countSql = @"SELECT count(id) FROM dbo.tbAcupoint where IsDelete=0"; var result = new BaseResult <AcupointEntity>(); try { var entity = await GetCount(countSql); if (entity > -1) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = new PageData <AcupointEntity> { list = { }, total = 1 }; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增收藏记录. /// </summary> /// <param name="entity">.</param> /// <returns>.</returns> public async Task <BaseResult <UserCollectEntity> > Add(UserCollectEntity entity) { string insertSql = @"INSERT INTO dbo.tbUserCollect(userId, objId,type,name,createDate) VALUES(@userId, @objId,@type,@name,getdate()) select @@identity"; var result = new BaseResult <UserCollectEntity>(); try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 判断用户是否收藏. /// </summary> /// <param name="query">.</param> /// <returns>.</returns> public async Task <BaseResult <IsCollectDTO> > IsCollect(IsCollectDTO query) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"SELECT * FROM dbo.tbUserCollect WHERE userId = {0} AND objId = {1} AND type={2}", query.userId, query.objId, query.type); var result = new BaseResult <IsCollectDTO>(); try { var i = await DetailBy(sb.ToString()); if (i != null) { query.isCollect = true; } else { query.isCollect = false; } result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = new PageData <IsCollectDTO> { list = new List <IsCollectDTO>() { query }, total = 1 }; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <SickEntity> > Add(SickEntity entity) { string insertSql = @"INSERT INTO dbo.tbSick(title, overview,acupoint,pathogeny,analysis,food) VALUES(@title, @overview,@acupoint,@pathogeny,@analysis,@food) select @@identity"; var result = new BaseResult <SickEntity>(); try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <AcupointEntity> > Add(AcupointEntity entity) { string insertSql = @"INSERT INTO dbo.tbAcupoint(name, findout,overview,info,handle,image) VALUES(@name, @findout,@overview,@info,@handle,@image) select @@identity"; var result = new BaseResult <AcupointEntity>(); try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 登录. /// </summary> /// <param name="entity">The entity<see cref="UserEntity"/>.</param> /// <returns>.</returns> public async Task <BaseResult <UserEntity> > Login(UserEntity entity) { var result = new BaseResult <UserEntity>(); string selectSql = string.Format(@"SELECT * FROM dbo.tbUser where IsDelete=0 and userName='******' and passWord='******'", entity.userName, entity.passWord); try { var qList = await Select(selectSql); if (qList.Count > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = new PageData <UserEntity> { list = qList, total = qList.Count }; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = "帐号或密码错误!"; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 更新. /// </summary> /// <param name="modal">The modal<see cref="UserDTO"/>.</param> /// <returns>.</returns> public async Task <BaseResult <UserEntity> > Update(UserDTO modal) { string updateSql = string.Format(@"UPDATE dbo.tbUser SET passWord='******',isManager={1} where userId={2}", modal.newPassword, modal.isManager, modal.userId); var result = new BaseResult <UserEntity>(); UserEntity entity = new UserEntity() { userId = modal.userId, passWord = modal.newPassword, isManager = modal.isManager, }; try { await Update(entity, updateSql.ToString()); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 获取详细信息. /// </summary> /// <param name="Id">.</param> /// <returns>.</returns> public async Task <BaseResult <AcupointEntity> > Detail(int Id) { string detailSql = @"SELECT * FROM dbo.tbAcupoint WHERE id=@id"; var result = new BaseResult <AcupointEntity>(); try { var entity = await Detail(Id, detailSql); if (null != entity) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = new PageData <AcupointEntity> { list = new List <AcupointEntity>() { entity }, total = 1 }; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 批量删除. /// </summary> /// <param name="Ids">The Ids<see cref="int[]"/>.</param> /// <returns>影响的行数.</returns> public async Task <BaseResult <UserEntity> > DeleteList(int[] Ids) { string deleteSql = "update dbo.tbUser SET isDelete=1 WHERE userId in @userIds"; var result = new BaseResult <UserEntity>(); try { var i = await Delete(Ids, deleteSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 按条件删除. /// </summary> /// <param name="conditionStr">The conditionStr<see cref="string"/>.</param> /// <returns>受影响都行数.</returns> public async Task <BaseResult <UserEntity> > DeleteBy(string conditionStr) { string deleteSql = "UPDATE dbo.tbUser SET IsDelete=1 WHERE 1=1 and " + conditionStr; var result = new BaseResult <UserEntity>(); try { var i = await DeleteBy(deleteSql); if (null != i) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 修改. /// </summary> /// <param name="entity">.</param> /// <returns>.</returns> public async Task <BaseResult <AcupointEntity> > Update(AcupointEntity entity) { StringBuilder sb = new StringBuilder(); string detailSql = @"SELECT * FROM dbo.tbAcupoint WHERE id=@id"; var i = await Detail(entity.id, detailSql); if (i == null) { throw new Exception("数据不存在"); } sb.AppendFormat(@"UPDATE dbo.tbAcupoint SET name = '{0}', findout ='{1}', overview = '{2}', info ='{3}',handle='{4}',image='{5}' WHERE id={6} ", entity.name, entity.findout, entity.overview, entity.info, entity.handle, entity.image, entity.id); var result = new BaseResult <AcupointEntity>(); try { await Update(entity, sb.ToString()); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <FoodEntity> > Add(FoodEntity entity) { string insertSql = @"INSERT INTO dbo.tbFood(name, image,material,method,act) VALUES(@name, @image,@material,@method,@act) select @@identity"; var result = new BaseResult <FoodEntity>(); try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增 /// </summary> /// <param name="entity">数据实体</param> /// <returns>返回主键值</returns> public async Task <BaseResult <UserEntity> > Add(UserEntity entity) { string insertSql = @"INSERT INTO [dbo].[tbUser](userName, passWord,age) VALUES(@userName, @passWord,@age) select @@identity"; var result = new BaseResult <UserEntity>(); try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); result.code = ResultKey.RETURN_EXCEPTION_CODE; result.desc = ResultKey.RETURN_EXCEPTION_DESC; } return(result); }
/// <summary> /// 获取分页数据. /// </summary> /// <param name="pageIndex">页码.</param> /// <param name="pageSize">页数.</param> /// <param name="SortRule">The SortRule<see cref="int"/>.</param> /// <returns>.</returns> public async Task <BaseResult <AcupointEntity> > GetListByPage(int pageIndex, int pageSize, int SortRule = 1) { string tableName = "tbAcupoint"; string where = " IsDelete=0"; string orderby = "id "; if (SortRule == 1) { orderby += " desc"; } else { orderby += " asc"; } pageSize = pageSize < 1 ? 10 : pageSize; int skip = 1; if (pageIndex > 0) { skip = (pageIndex - 1) * pageSize + 1; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("SELECT COUNT(1) FROM {0} where {1};", tableName, where); sb.AppendFormat(@"SELECT * FROM(SELECT ROW_NUMBER() OVER(ORDER BY {2}) AS RowNum,* FROM {0} WHERE {1} ) AS result WHERE RowNum >= {3} AND RowNum <= {4} ORDER BY {2}", tableName, where, orderby, skip, pageIndex * pageSize); var result = new BaseResult <AcupointEntity>(); try { var pageData = await GetPageList(sb.ToString()); if (pageData.total > -1) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = pageData; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 分页 新版. /// </summary> /// <param name="models">.</param> /// <returns>.</returns> public async Task <BaseResult <FoodEntity> > GetList(QueryDTO models) { string tableName = "tbFood"; string where = " IsDelete=0"; string orderby = "id "; if (models.sortRule == 1) { orderby += " DESC"; } else { orderby += " ASC"; } int skip = (models.pageIndex - 1) * models.pageSize + 1; if (models.name != null) { where = where + "AND name LIKE '%" + models.name + "%'"; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("SELECT COUNT(1) FROM {0} WHERE {1};", tableName, where); sb.AppendFormat(@"SELECT * FROM(SELECT ROW_NUMBER() OVER(ORDER BY {2}) AS RowNum,* FROM {0} WHERE {1} ) AS result WHERE RowNum >= {3} AND RowNum <= {4} ORDER BY {2}", tableName, where, orderby, skip, models.pageIndex * models.pageSize); var result = new BaseResult <FoodEntity>(); try { var pageData = await GetPageList(sb.ToString()); if (pageData.total > -1) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = pageData; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 获取分页数据. /// </summary> /// <param name="modal">The modal<see cref="UserCollectQueryDTO"/>.</param> /// <returns>.</returns> public async Task <BaseResult <UserCollectEntity> > GetCollectList(UserCollectQueryDTO modal) { string tableName = "tbUserCollect"; //string where = " IsDelete=0"; string orderby = "id "; if (modal.sortRule == 1) { orderby += " desc"; } else { orderby += " asc"; } int skip = (modal.pageIndex - 1) * modal.pageSize + 1; StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"SELECT COUNT(1) FROM {0} where 1=1 AND type={1} AND userId={2};", tableName, modal.type, modal.userId); sb.AppendFormat(@"SELECT * FROM(SELECT ROW_NUMBER() OVER(ORDER BY {1}) AS RowNum,* FROM {0} WHERE 1=1 ) AS result WHERE RowNum >= {2} AND RowNum <= {3} AND type={4} AND userId={5} ORDER BY {1}", tableName, orderby, skip, modal.pageIndex * modal.pageSize, modal.type, modal.userId); var result = new BaseResult <UserCollectEntity>(); try { var pageData = await GetPageList(sb.ToString()); if (pageData.total > -1) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = pageData; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 删除收藏记录. /// </summary> /// <param name="entity">The entity<see cref="UserCollectEntity"/>.</param> /// <returns>.</returns> public async Task <BaseResult <UserCollectEntity> > Delete(UserCollectEntity entity) { string deleteSql = string.Format("delete tbUserCollect where userId={0} and objId={1} and type={2}", entity.userId, entity.objId, entity.type); var result = new BaseResult <UserCollectEntity>(); try { int?i = await DeleteReal(deleteSql); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
public ActionResult <IEnumerable <string> > Get() { var domain222 = _testInterface.add(1, 2); #region redis _distributedCache.SetString("name", "zhangsan"); var value = _distributedCache.GetString("name"); #endregion var domaincache = _cache.Get("getkey"); if (domaincache == null) { var domain = _testInterface.add(1, 2); _cache.Set("getkey", domain); } //var aa = "dfasdfas"; //int bb = Convert.ToInt32(aa); NlogHelper.InfoLog("1234123"); return(new string[] { "value1", "value2" }); }
/// <summary> /// 删除 逻辑删除. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <SickEntity> > Delete(SickEntity entity) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"UPDATE dbo.tbSick SET IsDelete = 1 WHERE id = {0}", entity.id); var result = new BaseResult <SickEntity>(); try { var i = await Delete(entity.id, sb.ToString()); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 修改. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <SickEntity> > Updata(SickEntity entity) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"UPDATE dbo.tbSick SET title = '{0}', overview ='{1}', acupoint = '{2}', food ='{3}', pathogeny ='{4}', analysis = '{5}' WHERE id={6} ", entity.title, entity.overview, entity.acupoint, entity.food, entity.pathogeny, entity.analysis, entity.id); var result = new BaseResult <SickEntity>(); try { await Update(entity, sb.ToString()); result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
/// <summary> /// 新增. /// </summary> /// <param name="entity">数据实体.</param> /// <returns>返回主键值.</returns> public async Task <BaseResult <UserEntity> > Add(UserEntity entity) { var result = new BaseResult <UserEntity>(); string countSql = string.Format(@"SELECT count(userId) FROM dbo.tbUser where IsDelete=0 and userName='******'", entity.userName); int? n = await GetCount(countSql); if (n > 0) { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = "用户名已存在!"; return(result); } string insertSql = @"INSERT INTO dbo.tbUser (userName, passWord,age) VALUES(@userName, @passWord,@age) select @@identity"; try { var i = await Add(entity, insertSql); if (null != i && i > 0) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
public void RunAtTimeOf(DateTime now) { NlogHelper.InfoLog("1234123"); }