public int AddNavigation(Navigation model) { string cmdText = @" DECLARE @NEWID INT SET XACT_ABORT ON BEGIN TRAN INSERT INTO [Navigation] (Name,Identifier,ParentId,LinkAddress,Icon,Sort,IsShow) values (@Name,@Identifier,@ParentId,@LinkAddress,@Icon,@Sort,@IsShow) SET @NEWID=@@IDENTITY UPDATE Navigation SET Sort=Sort+1 where ParentId=@ParentId and Sort>=@Sort SELECT @NEWID COMMIT"; SqlParameter[] parameters = { SqlParamHelper.MakeInParam("@Name",SqlDbType.VarChar,50,model.Name), SqlParamHelper.MakeInParam("@Identifier",SqlDbType.VarChar,50,model.Identifier), SqlParamHelper.MakeInParam("@ParentId",SqlDbType.Int,4,model.ParentId), SqlParamHelper.MakeInParam("@LinkAddress",SqlDbType.VarChar,200,model.LinkAddress), SqlParamHelper.MakeInParam("@Icon",SqlDbType.VarChar,50,model.Icon), SqlParamHelper.MakeInParam("@Sort",SqlDbType.Int,4,model.Sort), SqlParamHelper.MakeInParam("@IsShow",SqlDbType.Int,4,model.IsShow) }; int id = 0; using (IDataReader dataReader = SqlHelper.ExecuteReader(WriteConnectionString,CommandType.Text,cmdText,parameters)){ if(dataReader.Read()){ object obj = dataReader[0]; if(obj != null && obj != DBNull.Value){ id = Convert.ToInt32(obj); } } } return id; }
private void AddMenu() { Navigation model = new Navigation { Name = GetRequestString("Name"), Identifier = GetRequestString("Name"), ParentId = GetRequestString("Parent").ToInt32(0), LinkAddress = GetRequestString("Link"), Icon = GetRequestString("icon"), Sort = GetRequestString("sort").ToInt32(0), IsShow = GetRequestString("Isshow").ToInt32(0) }; _AuthorizeService.AddNavigation(model); }
public int AddNavigation(Navigation model) { return _AuthorizeRepository.AddNavigation(model); }
public int UpdateNavigation(Navigation model) { return _AuthorizeRepository.UpdateNavigation(model); }
public int UpdateNavigation(Navigation model) { string cmdText = @" UPDATE [Navigation] SET Name=@Name,Identifier=@Identifier,ParentId=@ParentId,LinkAddress=@LinkAddress,Icon=@Icon,Sort=@Sort,IsShow=@IsShow WHERE Id=@Id"; SqlParameter[] parameters = { SqlParamHelper.MakeInParam("@Id",SqlDbType.Int,4,model.Id), SqlParamHelper.MakeInParam("@Name",SqlDbType.VarChar,50,model.Name), SqlParamHelper.MakeInParam("@Identifier",SqlDbType.VarChar,50,model.Identifier), SqlParamHelper.MakeInParam("@ParentId",SqlDbType.Int,4,model.ParentId), SqlParamHelper.MakeInParam("@LinkAddress",SqlDbType.VarChar,200,model.LinkAddress), SqlParamHelper.MakeInParam("@Icon",SqlDbType.VarChar,50,model.Icon), SqlParamHelper.MakeInParam("@Sort",SqlDbType.Int,4,model.Sort), SqlParamHelper.MakeInParam("@IsShow",SqlDbType.Int,4,model.IsShow) }; return SqlHelper.ExecuteNonQuery(WriteConnectionString,CommandType.Text,cmdText,parameters); }