public void Edit(MpMenuLocationDetailsInfo info) { var sqlTxt = @"update mp_menu set Name=@Name,`Type`=@Type,`Key`=@Key,`Url`=@Url where Id=@Id;"; using (DbCommand cmd = DbInstance.GetSqlStringCommand(sqlTxt)) { SetCommandParameter(cmd, "Id", DbType.Int64, info.Id); SetCommandParameter(cmd, "Name", DbType.String, info.Name); SetCommandParameter(cmd, "Type", DbType.String, info.Type); SetCommandParameter(cmd, "Key", DbType.String, info.Key); SetCommandParameter(cmd, "Url", DbType.String, info.Url); ExecSql(cmd); } if (!IsEmptyCollection(info.CategoryIds)) { sqlTxt = @"delete from mp_menu_relation where MenuId=" + info.Id + ";" + "insert into mp_menu_relation (MenuId,CategoryId) values "; var buf = new List <string>(); foreach (var item in info.CategoryIds) { buf.Add(string.Format("({0},{1})", info.Id, item)); } sqlTxt += string.Join(",", buf); ExecSql(sqlTxt); } }
public long Add(MpMenuLocationDetailsInfo info) { var sqlTxt = @"insert into mp_menu (ParentId,Name,`Type`,`Key`,`Url`,SortOrder) values (@ParentId,@Name,@Type,@Key,@Url,@SortOrder); select last_insert_id();"; var sortOrder = GetSortOrder(info.ParentId); long id; using (DbCommand cmd = DbInstance.GetSqlStringCommand(sqlTxt)) { SetCommandParameter(cmd, "ParentId", DbType.Int64, info.ParentId); SetCommandParameter(cmd, "Name", DbType.String, info.Name); SetCommandParameter(cmd, "Type", DbType.String, info.Type); SetCommandParameter(cmd, "Key", DbType.String, info.Key); SetCommandParameter(cmd, "Url", DbType.String, info.Url); SetCommandParameter(cmd, "SortOrder", DbType.Int32, sortOrder); id = GetLong(cmd); } if (!IsEmptyCollection(info.CategoryIds)) { sqlTxt = "insert into mp_menu_relation (MenuId,CategoryId) values "; var buf = new List <string>(); foreach (var item in info.CategoryIds) { buf.Add(string.Format("({0},{1})", id, item)); } sqlTxt += string.Join(",", buf); ExecSql(sqlTxt); } return(id); }